aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/cpp
diff options
context:
space:
mode:
authorGravatar Sree Kuchibhotla <sreek@google.com>2016-09-29 17:53:29 -0700
committerGravatar Sree Kuchibhotla <sreek@google.com>2016-09-29 17:53:29 -0700
commit3b2bc2deb1a249fd6d260adb50c39064ef5f9c2c (patch)
treedfe0e8238e1c9abc3f7b74c1dce90f1df5e2cb84 /src/cpp
parenta2b2ac80d478d5552727488ec73579970b6f70fd (diff)
tsan failures
Diffstat (limited to 'src/cpp')
-rw-r--r--src/cpp/rpcmanager/grpc_rpc_manager.cc33
1 files changed, 18 insertions, 15 deletions
diff --git a/src/cpp/rpcmanager/grpc_rpc_manager.cc b/src/cpp/rpcmanager/grpc_rpc_manager.cc
index 58b337da63..2299dbdcd3 100644
--- a/src/cpp/rpcmanager/grpc_rpc_manager.cc
+++ b/src/cpp/rpcmanager/grpc_rpc_manager.cc
@@ -59,12 +59,14 @@ GrpcRpcManager::GrpcRpcManager(int min_pollers, int max_pollers)
: shutdown_(false),
num_pollers_(0),
min_pollers_(min_pollers),
- max_pollers_(max_pollers == -1 ? INT_MAX: max_pollers),
+ max_pollers_(max_pollers == -1 ? INT_MAX : max_pollers),
num_threads_(0) {}
GrpcRpcManager::~GrpcRpcManager() {
- std::unique_lock<grpc::mutex> lock(mu_);
- GPR_ASSERT(num_threads_ == 0);
+ {
+ std::unique_lock<grpc::mutex> lock(mu_);
+ GPR_ASSERT(num_threads_ == 0);
+ }
CleanupCompletedThreads();
}
@@ -87,8 +89,16 @@ bool GrpcRpcManager::IsShutdown() {
}
void GrpcRpcManager::MarkAsCompleted(GrpcRpcManagerThread* thd) {
- std::unique_lock<grpc::mutex> lock(list_mu_);
- completed_threads_.push_back(thd);
+ {
+ std::unique_lock<grpc::mutex> list_lock(list_mu_);
+ completed_threads_.push_back(thd);
+ }
+
+ grpc::unique_lock<grpc::mutex> lock(mu_);
+ num_threads_--;
+ if (num_threads_ == 0) {
+ shutdown_cv_.notify_one();
+ }
}
void GrpcRpcManager::CleanupCompletedThreads() {
@@ -169,17 +179,10 @@ void GrpcRpcManager::MainWorkLoop() {
}
} while (MaybeContinueAsPoller());
- // If we are here, either GrpcRpcManager is shutting down or it already has
- // enough threads. In both cases, current thread can be terminated
- {
- grpc::unique_lock<grpc::mutex> lock(mu_);
- num_threads_--;
- if (num_threads_ == 0) {
- shutdown_cv_.notify_one();
- }
- }
-
CleanupCompletedThreads();
+
+ // If we are here, either GrpcRpcManager is shutting down or it already has
+ // enough threads.
}
} // namespace grpc