mirror of
https://github.com/love2d/love.git
synced 2026-08-14 01:20:56 +02:00
Make Channels more thread-safe (I know, I know..)
--HG-- branch : minor
This commit is contained in:
+2
-2
@@ -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:
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -54,6 +54,8 @@ namespace thread
|
||||
Variant *peek();
|
||||
int count();
|
||||
void clear();
|
||||
|
||||
void release();
|
||||
}; // Channel
|
||||
} // thread
|
||||
} // love
|
||||
|
||||
Reference in New Issue
Block a user