mirror of
https://github.com/love2d/love.git
synced 2026-08-16 08:11:02 +02:00
We don't need a mutex lock in Channel::retain/release... I think.
This commit is contained in:
+2
-2
@@ -59,14 +59,14 @@ public:
|
||||
* Retains the Object, i.e. increases the
|
||||
* reference count by one.
|
||||
**/
|
||||
virtual void retain();
|
||||
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.
|
||||
**/
|
||||
virtual void release();
|
||||
void release();
|
||||
|
||||
private:
|
||||
|
||||
|
||||
@@ -58,12 +58,17 @@ Channel *Channel::getChannel(const std::string &name)
|
||||
if (!namedChannelMutex)
|
||||
namedChannelMutex = newMutex();
|
||||
|
||||
Lock l(namedChannelMutex);
|
||||
if (!namedChannels.count(name))
|
||||
namedChannels[name] = new Channel(name);
|
||||
else
|
||||
namedChannels[name]->retain();
|
||||
Lock lock(namedChannelMutex);
|
||||
|
||||
auto it = namedChannels.find(name);
|
||||
|
||||
if (it != namedChannels.end())
|
||||
{
|
||||
it->second->retain();
|
||||
return it->second;
|
||||
}
|
||||
|
||||
namedChannels[name] = new Channel(name);
|
||||
return namedChannels[name];
|
||||
}
|
||||
|
||||
@@ -92,7 +97,10 @@ Channel::~Channel()
|
||||
delete cond;
|
||||
|
||||
if (named)
|
||||
{
|
||||
Lock l(namedChannelMutex);
|
||||
namedChannels.erase(name);
|
||||
}
|
||||
}
|
||||
|
||||
unsigned long Channel::push(const Variant &var)
|
||||
@@ -196,22 +204,5 @@ void Channel::unlockMutex()
|
||||
mutex->unlock();
|
||||
}
|
||||
|
||||
void Channel::retain()
|
||||
{
|
||||
EmptyLock l;
|
||||
if (named)
|
||||
l.setLock(namedChannelMutex);
|
||||
|
||||
Object::retain();
|
||||
}
|
||||
|
||||
void Channel::release()
|
||||
{
|
||||
EmptyLock l;
|
||||
if (named)
|
||||
l.setLock(namedChannelMutex);
|
||||
|
||||
Object::release();
|
||||
}
|
||||
} // thread
|
||||
} // love
|
||||
|
||||
@@ -54,9 +54,6 @@ public:
|
||||
int getCount();
|
||||
void clear();
|
||||
|
||||
void retain();
|
||||
void release();
|
||||
|
||||
private:
|
||||
|
||||
Channel(const std::string &name);
|
||||
|
||||
@@ -27,8 +27,7 @@ namespace thread
|
||||
|
||||
LuaThread *ThreadModule::newThread(const std::string &name, love::Data *data)
|
||||
{
|
||||
LuaThread *lt = new LuaThread(name, data);
|
||||
return lt;
|
||||
return new LuaThread(name, data);
|
||||
}
|
||||
|
||||
Channel *ThreadModule::newChannel()
|
||||
|
||||
Reference in New Issue
Block a user