Commits

Anonymous committed af6dc88 Merge

Merging upstream changes

Comments (0)

Files changed (2)

src/modules/thread/sdl/Thread.cpp

 
 	ThreadVariant *Thread::receive(const std::string & name)
 	{
-		lock();
 		ThreadVariant *v = comm->getValue(name);
 		if (v)
 			v->retain();
-		unlock();
 		return v;
 	}
 
 	ThreadVariant *Thread::demand(const std::string & name)
 	{
-		lock();
 		ThreadVariant *v = comm->getValue(name);
 		while (!v)
 		{
 			v = comm->getValue(name);
 		}
 		v->retain();
-		unlock();
 		return v;
 	}
 
 	void Thread::clear(const std::string & name)
 	{
-		lock();
 		comm->clearValue(name);
-		unlock();
 	}
 
 	void Thread::send(const std::string & name, ThreadVariant *v)
 	{
-		lock();
-		comm->setValue(name, v);
-		unlock();
+		lock(); //this function explicitly locks
+		comm->setValue(name, v); //because we need
+		unlock(); //it to unlock here for the cond
 		SDL_CondBroadcast(cond);
 	}
 

src/modules/thread/sdl/wrap_Thread.cpp

 	{
 		Thread *t = luax_checkthread(L, 1);
 		std::string name = luax_checklstring(L, 2);
+		t->lock();
 		ThreadVariant *v = t->receive(name);
 		if (!v)
 		{
 			return 1;
 		}
 		t->clear(name);
+		t->unlock();
 		switch(v->type)
 		{
 			case BOOLEAN:
 	{
 		Thread *t = luax_checkthread(L, 1);
 		std::string name = luax_checklstring(L, 2);
+		t->lock();
 		ThreadVariant *v = t->demand(name);
 		if (!v)
 		{
 			return 1;
 		}
 		t->clear(name);
+		t->unlock();
 		switch(v->type)
 		{
 			case BOOLEAN:
 			return luaL_error(L, "Expected boolean, number, string or userdata");
 		}
 		t->send(name, v);
+		t->lock();
 		v->release();
+		t->unlock();
 		return 0;
 	}