mirror of https://github.com/axmolengine/axmol.git
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:
commit
2ec85f8c4e
|
@ -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();
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue