AsyncRPCOperationId key;
std::shared_ptr<AsyncRPCOperation> operation;
{
- std::unique_lock< std::mutex > guard(lock_);
+ std::unique_lock<std::mutex> guard(lock_);
while (operation_id_queue_.empty() && !isClosed() && !isFinishing()) {
this->condition_.wait(guard);
}
* Call cancel() on all operations
*/
void AsyncRPCQueue::cancelAllOperations() {
- std::unique_lock< std::mutex > guard(lock_);
+ std::lock_guard<std::mutex> guard(lock_);
for (auto key : operation_map_) {
key.second->cancel();
}
* Return the number of operations in the queue
*/
size_t AsyncRPCQueue::getOperationCount() const {
- std::unique_lock< std::mutex > guard(lock_);
+ std::lock_guard<std::mutex> guard(lock_);
return operation_id_queue_.size();
}
* 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<std::mutex> guard(lock_);
workers_.emplace_back( std::thread(&AsyncRPCQueue::run, this, ++workerCounter) );
}
* Return the number of worker threads spawned by the queue
*/
size_t AsyncRPCQueue::getNumberOfWorkers() const {
+ std::lock_guard<std::mutex> guard(lock_);
return workers_.size();
}
* Return a list of all known operation ids found in internal storage.
*/
std::vector<AsyncRPCOperationId> AsyncRPCQueue::getAllOperationIds() const {
- std::unique_lock< std::mutex > guard(lock_);
+ std::lock_guard<std::mutex> guard(lock_);
std::vector<AsyncRPCOperationId> v;
for(auto & entry: operation_map_) {
v.push_back(entry.first);
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<std::mutex> guard(lock_);
this->condition_.notify_all();
}