We don't need a mutex lock in Channel::retain/release... I think.

This commit is contained in:
Alex Szpakowski
2016-02-26 18:38:39 -04:00
parent 4ca6106d7a
commit e08374fdd1
4 changed files with 16 additions and 29 deletions
+2 -2
View File
@@ -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:
+13 -22
View File
@@ -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
-3
View File
@@ -54,9 +54,6 @@ public:
int getCount();
void clear();
void retain();
void release();
private:
Channel(const std::string &name);
+1 -2
View File
@@ -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()