use lock_guard

This commit is contained in:
dimon4eg 2019-05-09 00:20:26 +03:00
parent 2727d39fa4
commit 28ae70ed20

View File

@ -56,9 +56,10 @@ namespace ix
message->openInfo = openInfo; message->openInfo = openInfo;
message->closeInfo = closeInfo; message->closeInfo = closeInfo;
_messagesMutex.lock(); {
_messages.emplace_back(std::move(message)); std::lock_guard<std::mutex> lock(_messagesMutex);
_messagesMutex.unlock(); _messages.emplace_back(std::move(message));
}
}); });
} }
} }
@ -72,14 +73,13 @@ namespace ix
WebSocketMessageQueue::MessageDataPtr WebSocketMessageQueue::popMessage() WebSocketMessageQueue::MessageDataPtr WebSocketMessageQueue::popMessage()
{ {
MessageDataPtr message; MessageDataPtr message;
std::lock_guard<std::mutex> lock(_messagesMutex);
_messagesMutex.lock();
if (!_messages.empty()) if (!_messages.empty())
{ {
message = std::move(_messages.front()); message = std::move(_messages.front());
_messages.pop_front(); _messages.pop_front();
} }
_messagesMutex.unlock();
return message; return message;
} }