aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/cpp/thread_manager
diff options
context:
space:
mode:
authorGravatar Vijay Pai <vpai@google.com>2018-08-15 10:13:22 -0700
committerGravatar Vijay Pai <vpai@google.com>2018-08-15 10:13:22 -0700
commitd9781df47461e10ec364290955313773cd1876e1 (patch)
tree8bb02decd8c034989e56d33d50eec1705525662d /src/cpp/thread_manager
parent14ad82a76de99de39460d901cf44767308859ae0 (diff)
Address reviewer comments
Diffstat (limited to 'src/cpp/thread_manager')
-rw-r--r--src/cpp/thread_manager/thread_manager.cc19
1 files changed, 10 insertions, 9 deletions
diff --git a/src/cpp/thread_manager/thread_manager.cc b/src/cpp/thread_manager/thread_manager.cc
index e48bf951ea..3e8606a76f 100644
--- a/src/cpp/thread_manager/thread_manager.cc
+++ b/src/cpp/thread_manager/thread_manager.cc
@@ -166,9 +166,10 @@ void ThreadManager::MainWorkLoop() {
case WORK_FOUND:
// If we got work and there are now insufficient pollers and there is
// quota available to create a new thread, start a new poller thread
- bool got_thread;
+ bool resource_exhausted = false;
if (!shutdown_ && num_pollers_ < min_pollers_) {
if (grpc_resource_user_allocate_threads(resource_user_, 1)) {
+ // We can allocate a new poller thread
num_pollers_++;
num_threads_++;
if (num_threads_ > max_active_threads_sofar_) {
@@ -177,26 +178,26 @@ void ThreadManager::MainWorkLoop() {
// Drop lock before spawning thread to avoid contention
lock.unlock();
new WorkerThread(this);
- got_thread = true;
} else if (num_pollers_ > 0) {
// There is still at least some thread polling, so we can go on
- // even though we couldn't allocate a new thread
+ // even though we are below the number of pollers that we would
+ // like to have (min_pollers_)
lock.unlock();
- got_thread = true;
} else {
// There are no pollers to spare and we couldn't allocate
// a new thread, so resources are exhausted!
lock.unlock();
- got_thread = false;
+ resource_exhausted = true;
}
} else {
- // Drop lock for consistency with above branch
+ // There are a sufficient number of pollers available so we can do
+ // the work and continue polling with our existing poller threads
lock.unlock();
- got_thread = true;
}
// Lock is always released at this point - do the application work
- // or return resource exhausted
- DoWork(tag, ok, got_thread);
+ // or return resource exhausted if there is new work but we couldn't
+ // get a thread in which to do it.
+ DoWork(tag, ok, !resource_exhausted);
// Take the lock again to check post conditions
lock.lock();
// If we're shutdown, we should finish at this point.