From 95beab22843369189836828a0116a9760482ce7f Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Thu, 12 Jan 2017 13:41:52 -0800 Subject: Uncover the badness --- src/cpp/server/dynamic_thread_pool.cc | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'src/cpp/server/dynamic_thread_pool.cc') diff --git a/src/cpp/server/dynamic_thread_pool.cc b/src/cpp/server/dynamic_thread_pool.cc index 1fdc2edb25..e7721bc990 100644 --- a/src/cpp/server/dynamic_thread_pool.cc +++ b/src/cpp/server/dynamic_thread_pool.cc @@ -31,12 +31,16 @@ * */ +#include "src/cpp/server/dynamic_thread_pool.h" + #include #include -#include "src/cpp/server/dynamic_thread_pool.h" +#include namespace grpc { +static thread_local bool g_is_dynamic_thread_pool_thread; + DynamicThreadPool::DynamicThread::DynamicThread(DynamicThreadPool* pool) : pool_(pool), thd_(new std::thread(&DynamicThreadPool::DynamicThread::ThreadFunc, @@ -47,6 +51,7 @@ DynamicThreadPool::DynamicThread::~DynamicThread() { } void DynamicThreadPool::DynamicThread::ThreadFunc() { + g_is_dynamic_thread_pool_thread = true; pool_->ThreadFunc(); // Now that we have killed ourselves, we should reduce the thread count std::unique_lock lock(pool_->mu_); @@ -99,11 +104,13 @@ DynamicThreadPool::DynamicThreadPool(int reserve_threads) void DynamicThreadPool::ReapThreads(std::list* tlist) { for (auto t = tlist->begin(); t != tlist->end(); t = tlist->erase(t)) { + gpr_log(GPR_DEBUG, "delete %p", *t); delete *t; } } DynamicThreadPool::~DynamicThreadPool() { + GPR_ASSERT(!g_is_dynamic_thread_pool_thread); std::unique_lock lock(mu_); shutdown_ = true; cv_.notify_all(); -- cgit v1.2.3 From 85e15a0bdedf18928dd19735c590bd59ddd4e831 Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Thu, 12 Jan 2017 13:42:41 -0800 Subject: Spam cleanup --- src/cpp/server/dynamic_thread_pool.cc | 1 - 1 file changed, 1 deletion(-) (limited to 'src/cpp/server/dynamic_thread_pool.cc') diff --git a/src/cpp/server/dynamic_thread_pool.cc b/src/cpp/server/dynamic_thread_pool.cc index e7721bc990..0361768c04 100644 --- a/src/cpp/server/dynamic_thread_pool.cc +++ b/src/cpp/server/dynamic_thread_pool.cc @@ -104,7 +104,6 @@ DynamicThreadPool::DynamicThreadPool(int reserve_threads) void DynamicThreadPool::ReapThreads(std::list* tlist) { for (auto t = tlist->begin(); t != tlist->end(); t = tlist->erase(t)) { - gpr_log(GPR_DEBUG, "delete %p", *t); delete *t; } } -- cgit v1.2.3 From 6d353e2a72d1313bc4d1e9938a1f5ffe157a4db4 Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Thu, 12 Jan 2017 21:23:00 -0800 Subject: Fix mac --- src/cpp/server/dynamic_thread_pool.cc | 3 --- 1 file changed, 3 deletions(-) (limited to 'src/cpp/server/dynamic_thread_pool.cc') diff --git a/src/cpp/server/dynamic_thread_pool.cc b/src/cpp/server/dynamic_thread_pool.cc index 0361768c04..afb5beaade 100644 --- a/src/cpp/server/dynamic_thread_pool.cc +++ b/src/cpp/server/dynamic_thread_pool.cc @@ -39,7 +39,6 @@ #include namespace grpc { -static thread_local bool g_is_dynamic_thread_pool_thread; DynamicThreadPool::DynamicThread::DynamicThread(DynamicThreadPool* pool) : pool_(pool), @@ -51,7 +50,6 @@ DynamicThreadPool::DynamicThread::~DynamicThread() { } void DynamicThreadPool::DynamicThread::ThreadFunc() { - g_is_dynamic_thread_pool_thread = true; pool_->ThreadFunc(); // Now that we have killed ourselves, we should reduce the thread count std::unique_lock lock(pool_->mu_); @@ -109,7 +107,6 @@ void DynamicThreadPool::ReapThreads(std::list* tlist) { } DynamicThreadPool::~DynamicThreadPool() { - GPR_ASSERT(!g_is_dynamic_thread_pool_thread); std::unique_lock lock(mu_); shutdown_ = true; cv_.notify_all(); -- cgit v1.2.3