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 * Retains the Object, i.e. increases the
* reference count by one. * reference count by one.
**/ **/
virtual void retain(); void retain();
/** /**
* Releases one reference to the Object, i.e. decrements the * Releases one reference to the Object, i.e. decrements the
* reference count by one, and potentially deletes the Object * reference count by one, and potentially deletes the Object
* if there are no more references. * if there are no more references.
**/ **/
virtual void release(); void release();
private: private:
+13 -22
View File
@@ -58,12 +58,17 @@ Channel *Channel::getChannel(const std::string &name)
if (!namedChannelMutex) if (!namedChannelMutex)
namedChannelMutex = newMutex(); namedChannelMutex = newMutex();
Lock l(namedChannelMutex); Lock lock(namedChannelMutex);
if (!namedChannels.count(name))
namedChannels[name] = new Channel(name);
else
namedChannels[name]->retain();
auto it = namedChannels.find(name);
if (it != namedChannels.end())
{
it->second->retain();
return it->second;
}
namedChannels[name] = new Channel(name);
return namedChannels[name]; return namedChannels[name];
} }
@@ -92,7 +97,10 @@ Channel::~Channel()
delete cond; delete cond;
if (named) if (named)
{
Lock l(namedChannelMutex);
namedChannels.erase(name); namedChannels.erase(name);
}
} }
unsigned long Channel::push(const Variant &var) unsigned long Channel::push(const Variant &var)
@@ -196,22 +204,5 @@ void Channel::unlockMutex()
mutex->unlock(); 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 } // thread
} // love } // love
-3
View File
@@ -54,9 +54,6 @@ public:
int getCount(); int getCount();
void clear(); void clear();
void retain();
void release();
private: private:
Channel(const std::string &name); 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 *ThreadModule::newThread(const std::string &name, love::Data *data)
{ {
LuaThread *lt = new LuaThread(name, data); return new LuaThread(name, data);
return lt;
} }
Channel *ThreadModule::newChannel() Channel *ThreadModule::newChannel()