mirror of
https://github.com/love2d/love.git
synced 2026-08-19 20:19:42 +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
|
* 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:
|
||||||
|
|
||||||
|
|||||||
@@ -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
|
||||||
|
|||||||
@@ -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);
|
||||||
|
|||||||
@@ -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()
|
||||||
|
|||||||
Reference in New Issue
Block a user