Merge pull request #8922 from TimothyZhang/do-not-lock-when-no-message-in-websocket

avoid locking when message queue is empty in websocket
This commit is contained in:
minggo 2014-12-25 14:09:35 +08:00
commit 2ec85f8c4e
1 changed files with 6 additions and 0 deletions

View File

@ -187,6 +187,12 @@ void WsThreadHelper::update(float dt)
{ {
WsMessage *msg = nullptr; 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 // Returns quickly if no message
_UIWsMessageQueueMutex.lock(); _UIWsMessageQueueMutex.lock();