Replace unique_lock with lock_guard, where appropriate, for consistency
This commit is contained in:
parent
a50fd5fdb7
commit
5e363861e0
|
@ -156,7 +156,7 @@ void AsyncRPCQueue::finish() {
|
||||||
* Call cancel() on all operations
|
* Call cancel() on all operations
|
||||||
*/
|
*/
|
||||||
void AsyncRPCQueue::cancelAllOperations() {
|
void AsyncRPCQueue::cancelAllOperations() {
|
||||||
std::unique_lock< std::mutex > guard(lock_);
|
std::lock_guard<std::mutex> guard(lock_);
|
||||||
for (auto key : operation_map_) {
|
for (auto key : operation_map_) {
|
||||||
key.second->cancel();
|
key.second->cancel();
|
||||||
}
|
}
|
||||||
|
@ -167,7 +167,7 @@ void AsyncRPCQueue::cancelAllOperations() {
|
||||||
* Return the number of operations in the queue
|
* Return the number of operations in the queue
|
||||||
*/
|
*/
|
||||||
size_t AsyncRPCQueue::getOperationCount() const {
|
size_t AsyncRPCQueue::getOperationCount() const {
|
||||||
std::unique_lock< std::mutex > guard(lock_);
|
std::lock_guard<std::mutex> guard(lock_);
|
||||||
return operation_id_queue_.size();
|
return operation_id_queue_.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -175,7 +175,7 @@ size_t AsyncRPCQueue::getOperationCount() const {
|
||||||
* Spawn a worker thread
|
* Spawn a worker thread
|
||||||
*/
|
*/
|
||||||
void AsyncRPCQueue::addWorker() {
|
void AsyncRPCQueue::addWorker() {
|
||||||
std::unique_lock< std::mutex > guard(lock_); // Todo: could just have a lock on the vector
|
std::lock_guard<std::mutex> guard(lock_);
|
||||||
workers_.emplace_back( std::thread(&AsyncRPCQueue::run, this, ++workerCounter) );
|
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.
|
* Return a list of all known operation ids found in internal storage.
|
||||||
*/
|
*/
|
||||||
std::vector<AsyncRPCOperationId> AsyncRPCQueue::getAllOperationIds() const {
|
std::vector<AsyncRPCOperationId> AsyncRPCQueue::getAllOperationIds() const {
|
||||||
std::unique_lock< std::mutex > guard(lock_);
|
std::lock_guard<std::mutex> guard(lock_);
|
||||||
std::vector<AsyncRPCOperationId> v;
|
std::vector<AsyncRPCOperationId> v;
|
||||||
for(auto & entry: operation_map_) {
|
for(auto & entry: operation_map_) {
|
||||||
v.push_back(entry.first);
|
v.push_back(entry.first);
|
||||||
|
@ -221,7 +221,7 @@ void AsyncRPCQueue::finishAndWait() {
|
||||||
void AsyncRPCQueue::wait_for_worker_threads() {
|
void AsyncRPCQueue::wait_for_worker_threads() {
|
||||||
// Notify any workers who are waiting, so they see the updated queue state
|
// Notify any workers who are waiting, so they see the updated queue state
|
||||||
{
|
{
|
||||||
std::unique_lock< std::mutex > guard(lock_);
|
std::lock_guard<std::mutex> guard(lock_);
|
||||||
this->condition_.notify_all();
|
this->condition_.notify_all();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue