mirror of
https://github.com/love2d/love.git
synced 2026-08-12 08:30:56 +02:00
More race conditions, what fun
This commit is contained in:
@@ -251,17 +251,14 @@ namespace sdl
|
||||
|
||||
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)
|
||||
{
|
||||
@@ -271,22 +268,19 @@ namespace sdl
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
@@ -76,6 +76,7 @@ namespace sdl
|
||||
{
|
||||
Thread *t = luax_checkthread(L, 1);
|
||||
std::string name = luax_checklstring(L, 2);
|
||||
t->lock();
|
||||
ThreadVariant *v = t->receive(name);
|
||||
if (!v)
|
||||
{
|
||||
@@ -83,6 +84,7 @@ namespace sdl
|
||||
return 1;
|
||||
}
|
||||
t->clear(name);
|
||||
t->unlock();
|
||||
switch(v->type)
|
||||
{
|
||||
case BOOLEAN:
|
||||
@@ -119,6 +121,7 @@ namespace sdl
|
||||
{
|
||||
Thread *t = luax_checkthread(L, 1);
|
||||
std::string name = luax_checklstring(L, 2);
|
||||
t->lock();
|
||||
ThreadVariant *v = t->demand(name);
|
||||
if (!v)
|
||||
{
|
||||
@@ -126,6 +129,7 @@ namespace sdl
|
||||
return 1;
|
||||
}
|
||||
t->clear(name);
|
||||
t->unlock();
|
||||
switch(v->type)
|
||||
{
|
||||
case BOOLEAN:
|
||||
@@ -248,7 +252,9 @@ namespace sdl
|
||||
return luaL_error(L, "Expected boolean, number, string or userdata");
|
||||
}
|
||||
t->send(name, v);
|
||||
t->lock();
|
||||
v->release();
|
||||
t->unlock();
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user