mirror of https://github.com/axmolengine/axmol.git
avoid locking when message queue is empty in websocket
This commit is contained in:
parent
e5ac916a17
commit
6d43d5e11e
|
@ -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