From 5e363861e0035bac02b5f773ee63ff88c02ba032 Mon Sep 17 00:00:00 2001 From: Simon Date: Wed, 7 Sep 2016 21:51:49 -0700 Subject: [PATCH] Replace unique_lock with lock_guard, where appropriate, for consistency --- src/asyncrpcqueue.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/asyncrpcqueue.cpp b/src/asyncrpcqueue.cpp index a6f35d367..d7d82557d 100644 --- a/src/asyncrpcqueue.cpp +++ b/src/asyncrpcqueue.cpp @@ -156,7 +156,7 @@ void AsyncRPCQueue::finish() { * Call cancel() on all operations */ void AsyncRPCQueue::cancelAllOperations() { - std::unique_lock< std::mutex > guard(lock_); + std::lock_guard guard(lock_); for (auto key : operation_map_) { key.second->cancel(); } @@ -167,7 +167,7 @@ void AsyncRPCQueue::cancelAllOperations() { * Return the number of operations in the queue */ size_t AsyncRPCQueue::getOperationCount() const { - std::unique_lock< std::mutex > guard(lock_); + std::lock_guard guard(lock_); return operation_id_queue_.size(); } @@ -175,7 +175,7 @@ size_t AsyncRPCQueue::getOperationCount() const { * Spawn a worker thread */ void AsyncRPCQueue::addWorker() { - std::unique_lock< std::mutex > guard(lock_); // Todo: could just have a lock on the vector + std::lock_guard guard(lock_); workers_.emplace_back( std::thread(&AsyncRPCQueue::run, this, ++workerCounter) ); } @@ -191,7 +191,7 @@ size_t AsyncRPCQueue::getNumberOfWorkers() const { * Return a list of all known operation ids found in internal storage. */ std::vector AsyncRPCQueue::getAllOperationIds() const { - std::unique_lock< std::mutex > guard(lock_); + std::lock_guard guard(lock_); std::vector v; for(auto & entry: operation_map_) { v.push_back(entry.first); @@ -221,7 +221,7 @@ void AsyncRPCQueue::finishAndWait() { void AsyncRPCQueue::wait_for_worker_threads() { // Notify any workers who are waiting, so they see the updated queue state { - std::unique_lock< std::mutex > guard(lock_); + std::lock_guard guard(lock_); this->condition_.notify_all(); }