From 28ae70ed20f6214badf5c446ac738d98e130cf70 Mon Sep 17 00:00:00 2001 From: dimon4eg Date: Thu, 9 May 2019 00:20:26 +0300 Subject: [PATCH] use lock_guard --- ixwebsocket/IXWebSocketMessageQueue.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/ixwebsocket/IXWebSocketMessageQueue.cpp b/ixwebsocket/IXWebSocketMessageQueue.cpp index b7c074f7..a62757bf 100644 --- a/ixwebsocket/IXWebSocketMessageQueue.cpp +++ b/ixwebsocket/IXWebSocketMessageQueue.cpp @@ -56,9 +56,10 @@ namespace ix message->openInfo = openInfo; message->closeInfo = closeInfo; - _messagesMutex.lock(); - _messages.emplace_back(std::move(message)); - _messagesMutex.unlock(); + { + std::lock_guard lock(_messagesMutex); + _messages.emplace_back(std::move(message)); + } }); } } @@ -72,14 +73,13 @@ namespace ix WebSocketMessageQueue::MessageDataPtr WebSocketMessageQueue::popMessage() { MessageDataPtr message; + std::lock_guard lock(_messagesMutex); - _messagesMutex.lock(); if (!_messages.empty()) { message = std::move(_messages.front()); _messages.pop_front(); } - _messagesMutex.unlock(); return message; }