From fe373075a474debcce829505cf3521139b4e1610 Mon Sep 17 00:00:00 2001 From: Bart van Strien Date: Mon, 20 Sep 2010 00:56:37 +0200 Subject: [PATCH] Thread now has access to mutex and cond as well, fixes bug where errors wouldn't get picked up --- src/modules/thread/sdl/Thread.cpp | 10 +++++++--- src/modules/thread/sdl/Thread.h | 5 ++++- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/modules/thread/sdl/Thread.cpp b/src/modules/thread/sdl/Thread.cpp index 648012c55..2ff9de136 100644 --- a/src/modules/thread/sdl/Thread.cpp +++ b/src/modules/thread/sdl/Thread.cpp @@ -49,9 +49,12 @@ namespace sdl lua_setfield(L, -2, "_curthread"); if(luaL_dostring(L, comm->getCode()) == 1) { + SDL_mutexP((SDL_mutex*) comm->mutex); ThreadVariant *v = new ThreadVariant(lua_tostring(L, -1)); comm->setValue("error", v); v->release(); + SDL_mutexV((SDL_mutex*) comm->mutex); + SDL_CondBroadcast((SDL_cond*) comm->cond); } lua_close(L); return 0; @@ -110,7 +113,8 @@ namespace sdl } } - ThreadData::ThreadData(const char *name, const char *code) + ThreadData::ThreadData(const char *name, const char *code, void *mutex, void *cond) + : mutex(mutex), cond(cond) { size_t len = strlen(name); this->name = new char[len+1]; @@ -174,18 +178,18 @@ namespace sdl this->data = new char[len+1]; memset(this->data, 0, len+1); memcpy(this->data, data->getData(), len); - comm = new ThreadData(name.c_str(), this->data); mutex = SDL_CreateMutex(); cond = SDL_CreateCond(); + comm = new ThreadData(name.c_str(), this->data, mutex, cond); } Thread::Thread(love::thread::ThreadModule *module, const std::string & name) : handle(0), module(module), name(name), data(0), isThread(false) { module->retain(); - comm = new ThreadData(name.c_str(), NULL); mutex = SDL_CreateMutex(); cond = SDL_CreateCond(); + comm = new ThreadData(name.c_str(), NULL, mutex, cond); } Thread::~Thread() diff --git a/src/modules/thread/sdl/Thread.h b/src/modules/thread/sdl/Thread.h index 69143d205..165b744d3 100644 --- a/src/modules/thread/sdl/Thread.h +++ b/src/modules/thread/sdl/Thread.h @@ -79,13 +79,16 @@ namespace sdl std::map shared; public: - ThreadData(const char *name, const char *code); + ThreadData(const char *name, const char *code, void *mutex, void *cond); ~ThreadData(); const char *getCode(); const char *getName(); ThreadVariant* getValue(const std::string & name); void clearValue(const std::string & name); void setValue(const std::string & name, ThreadVariant *v); + + void *mutex; + void *cond; }; class Thread : public love::Object