aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/cpp/rpcmanager
diff options
context:
space:
mode:
authorGravatar Sree Kuchibhotla <sreek@google.com>2016-07-19 17:47:46 -0700
committerGravatar Sree Kuchibhotla <sreek@google.com>2016-07-19 17:47:46 -0700
commitf95f125506373eb6c2ae630eae54badd871d2089 (patch)
treea411f951e74562f396509d404c4e5bc2bed6413d /src/cpp/rpcmanager
parentbb5519f5a52aeb23d32ec6ca817e008a65fdfa30 (diff)
Minor changes
Diffstat (limited to 'src/cpp/rpcmanager')
-rw-r--r--src/cpp/rpcmanager/grpc_rpc_manager.cc20
1 files changed, 14 insertions, 6 deletions
diff --git a/src/cpp/rpcmanager/grpc_rpc_manager.cc b/src/cpp/rpcmanager/grpc_rpc_manager.cc
index 7cffb23858..f0a4057857 100644
--- a/src/cpp/rpcmanager/grpc_rpc_manager.cc
+++ b/src/cpp/rpcmanager/grpc_rpc_manager.cc
@@ -103,6 +103,9 @@ void GrpcRpcManager::Initialize() {
}
}
+// If the number of pollers (i.e threads currently blocked in PollForWork()) is
+// less than max threshold (i.e max_pollers_) and the total number of threads is
+// below the maximum threshold, we can let the current thread continue as poller
bool GrpcRpcManager::MaybeContinueAsPoller() {
std::unique_lock<grpc::mutex> lock(mu_);
if (shutdown_ || num_pollers_ > max_pollers_ ||
@@ -114,6 +117,9 @@ bool GrpcRpcManager::MaybeContinueAsPoller() {
return true;
}
+// Create a new poller if the current number of pollers i.e num_pollers_ (i.e
+// threads currently blocked in PollForWork()) is below the threshold (i.e
+// min_pollers_) and the total number of threads is below the maximum threshold
void GrpcRpcManager::MaybeCreatePoller() {
grpc::unique_lock<grpc::mutex> lock(mu_);
if (!shutdown_ && num_pollers_ < min_pollers_ &&
@@ -130,24 +136,26 @@ void GrpcRpcManager::MainWorkLoop() {
bool is_work_found = false;
void* tag;
+ /*
+ 1. Poll for work (i.e PollForWork())
+ 2. After returning from PollForWork, reduce the number of pollers by 1
+ 3. Since we are short of one poller now, see if a new poller has to be
+ created (i.e see MaybeCreatePoller() for more details)
+ 4. Do the actual work (DoWork())
+ 5. After doing the work, see it this thread can resume polling work (i.e
+ see MaybeContinueAsPoller() for more details) */
do {
PollForWork(is_work_found, &tag);
- // Decrement num_pollers since this thread is no longer polling
{
grpc::unique_lock<grpc::mutex> lock(mu_);
num_pollers_--;
}
if (is_work_found) {
- // Start a new poller if needed
MaybeCreatePoller();
-
- // Do actual work
DoWork(tag);
}
-
- // Continue to loop if this thread can continue as a poller
} while (MaybeContinueAsPoller());
// If we are here, it means that the GrpcRpcManager already has enough threads