From eb8b37309d82d1cbbd5c51a9cf529d557778f981 Mon Sep 17 00:00:00 2001 From: Atlante45 Date: Thu, 17 Sep 2015 17:22:24 +0200 Subject: [PATCH] Use lock_guard when possible --- libraries/networking/src/udt/SendQueue.cpp | 39 ++++++++++------------ 1 file changed, 18 insertions(+), 21 deletions(-) diff --git a/libraries/networking/src/udt/SendQueue.cpp b/libraries/networking/src/udt/SendQueue.cpp index 45caec3aa9..1e7206c1ee 100644 --- a/libraries/networking/src/udt/SendQueue.cpp +++ b/libraries/networking/src/udt/SendQueue.cpp @@ -191,12 +191,10 @@ void SendQueue::nak(SequenceNumber start, SequenceNumber end) { _timeoutExpiryCount = 0; _lastReceiverResponse = uint64_t(QDateTime::currentMSecsSinceEpoch()); - std::unique_lock nakLocker(_naksLock); - - _naks.insert(start, end); - - // unlock the locked mutex before we notify - nakLocker.unlock(); + { + std::lock_guard nakLocker(_naksLock); + _naks.insert(start, end); + } // call notify_one on the condition_variable_any in case the send thread is sleeping waiting for losses to re-send _emptyCondition.notify_one(); @@ -207,24 +205,23 @@ void SendQueue::overrideNAKListFromPacket(ControlPacket& packet) { _timeoutExpiryCount = 0; _lastReceiverResponse = uint64_t(QDateTime::currentMSecsSinceEpoch()); - std::unique_lock nakLocker(_naksLock); - _naks.clear(); - - SequenceNumber first, second; - while (packet.bytesLeftToRead() >= (qint64)(2 * sizeof(SequenceNumber))) { - packet.readPrimitive(&first); - packet.readPrimitive(&second); + { + std::lock_guard nakLocker(_naksLock); + _naks.clear(); - if (first == second) { - _naks.append(first); - } else { - _naks.append(first, second); + SequenceNumber first, second; + while (packet.bytesLeftToRead() >= (qint64)(2 * sizeof(SequenceNumber))) { + packet.readPrimitive(&first); + packet.readPrimitive(&second); + + if (first == second) { + _naks.append(first); + } else { + _naks.append(first, second); + } } } - // unlock the mutex before we notify - nakLocker.unlock(); - // call notify_one on the condition_variable_any in case the send thread is sleeping waiting for losses to re-send _emptyCondition.notify_one(); } @@ -247,7 +244,7 @@ void SendQueue::sendHandshake() { void SendQueue::handshakeACK() { { - std::unique_lock locker { _handshakeMutex }; + std::lock_guard locker { _handshakeMutex }; _hasReceivedHandshakeACK = true; }