Browse Source

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

Alex Szpakowski 9 years ago
parent
commit
e08374fdd1

+ 2 - 2
src/common/Object.h

@@ -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
src/modules/thread/Channel.cpp

@@ -58,12 +58,17 @@ Channel *Channel::getChannel(const std::string &name)
 	if (!namedChannelMutex)
 	if (!namedChannelMutex)
 		namedChannelMutex = newMutex();
 		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];
 	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

+ 0 - 3
src/modules/thread/Channel.h

@@ -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
src/modules/thread/ThreadModule.cpp

@@ -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 lt;
+	return new LuaThread(name, data);
 }
 }
 
 
 Channel *ThreadModule::newChannel()
 Channel *ThreadModule::newChannel()