avoid locking when message queue is empty in websocket

This commit is contained in:
Timothy Zhang 2014-10-24 19:09:47 +08:00
parent e5ac916a17
commit 6d43d5e11e
1 changed files with 6 additions and 0 deletions

View File

@ -187,6 +187,12 @@ void WsThreadHelper::update(float dt)
{
WsMessage *msg = nullptr;
/* Avoid locking if, in most cases, the queue is empty. This could be a little faster.
size() is not thread-safe, it might return a strange value, but it should be OK in our scenario.
*/
if (0 == _UIWsMessageQueue->size())
return;
// Returns quickly if no message
_UIWsMessageQueueMutex.lock();