Make Channels more thread-safe (I know, I know..)

--HG--
branch : minor
This commit is contained in:
Bart van Strien
2012-07-04 20:22:54 +02:00
parent 399a6a6614
commit 777e97de2e
3 changed files with 20 additions and 5 deletions
+2 -2
View File
@@ -56,14 +56,14 @@ public:
* Retains the Object, i.e. increases the
* reference count by one.
**/
void retain();
virtual void retain();
/**
* Releases one reference to the Object, i.e. decrements the
* reference count by one, and potentially deletes the Object
* if there are no more references.
**/
void release();
virtual void release();
private:
+16 -3
View File
@@ -65,10 +65,7 @@ namespace thread
delete mutex;
delete cond;
if (named)
{
Lock l(namedChannelMutex);
namedChannels.erase(name);
}
}
void Channel::push(Variant *var)
@@ -133,6 +130,11 @@ namespace thread
void Channel::clear()
{
Lock l(mutex);
// We're already empty.
if (queue.empty())
return;
while (!queue.empty())
{
queue.front()->release();
@@ -144,5 +146,16 @@ namespace thread
if (named)
release();
}
void Channel::release()
{
if (named)
namedChannelMutex->lock();
Object::release();
if (named)
namedChannelMutex->unlock();
}
} // thread
} // love
+2
View File
@@ -54,6 +54,8 @@ namespace thread
Variant *peek();
int count();
void clear();
void release();
}; // Channel
} // thread
} // love