From 69a4cb448a2122ca7ec8160b4d0c7b9e149d1157 Mon Sep 17 00:00:00 2001 From: Simon Date: Wed, 7 Sep 2016 21:46:32 -0700 Subject: [PATCH] Move lock guard to start of addOperation to protect isClosed() and isFinishing() --- src/asyncrpcqueue.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/asyncrpcqueue.cpp b/src/asyncrpcqueue.cpp index 3dd13df5..9f59ee71 100644 --- a/src/asyncrpcqueue.cpp +++ b/src/asyncrpcqueue.cpp @@ -82,6 +82,7 @@ void AsyncRPCQueue::run(size_t workerId) { * Don't use std::make_shared(). */ void AsyncRPCQueue::addOperation(const std::shared_ptr &ptrOperation) { + std::lock_guard guard(lock_); // Don't add if queue is closed or finishing if (isClosed() || isFinishing()) { @@ -89,7 +90,6 @@ void AsyncRPCQueue::addOperation(const std::shared_ptr &ptrOp } AsyncRPCOperationId id = ptrOperation->getId(); - std::lock_guard< std::mutex > guard(lock_); operation_map_.emplace(id, ptrOperation); operation_id_queue_.push(id); this->condition_.notify_one();