Make mutex locks slightly more safe in some places (and correct in another...)

This commit is contained in:
Bart van Strien
2013-08-03 22:13:33 +02:00
parent 3e57cfd174
commit 1602c6de7a
2 changed files with 11 additions and 17 deletions
+6 -13
View File
@@ -125,13 +125,11 @@ void Channel::supply(Variant *var)
if (!var)
return;
mutex->lock();
Lock l(mutex);
unsigned long id = push(var);
while (!past(id, received))
cond->wait(mutex);
mutex->unlock();
}
Variant *Channel::pop()
@@ -157,11 +155,10 @@ Variant *Channel::pop()
Variant *Channel::demand()
{
Variant *var;
mutex->lock();
Lock l(mutex);
while (!(var = pop()))
cond->wait(mutex);
mutex->unlock();
return var;
}
@@ -218,24 +215,20 @@ void Channel::unlockMutex()
void Channel::retain()
{
EmptyLock l;
if (named)
namedChannelMutex->lock();
l.setLock(namedChannelMutex);
Object::retain();
if (named)
namedChannelMutex->unlock();
}
void Channel::release()
{
EmptyLock l;
if (named)
namedChannelMutex->lock();
l.setLock(namedChannelMutex);
Object::release();
if (named)
namedChannelMutex->unlock();
}
} // thread
} // love