diff options
author | 2018-03-02 16:16:04 -0800 | |
---|---|---|
committer | 2018-03-02 16:16:04 -0800 | |
commit | 162ae4f50c53cc6f1f3972c8fb63a5a5e78a1cb7 (patch) | |
tree | 4f92097047b116d84e606e92619d460978d76bcf /src | |
parent | 46ac366038cd692d732c2b97e60e87a23190c698 (diff) |
Remove std::thread, keep everything else unchanged (#13)
Diffstat (limited to 'src')
-rw-r--r-- | src/cpp/server/dynamic_thread_pool.cc | 16 | ||||
-rw-r--r-- | src/cpp/server/dynamic_thread_pool.h | 4 | ||||
-rw-r--r-- | src/cpp/thread_manager/thread_manager.cc | 15 | ||||
-rw-r--r-- | src/cpp/thread_manager/thread_manager.h | 10 |
4 files changed, 27 insertions, 18 deletions
diff --git a/src/cpp/server/dynamic_thread_pool.cc b/src/cpp/server/dynamic_thread_pool.cc index 81c78fe739..fe887486d1 100644 --- a/src/cpp/server/dynamic_thread_pool.cc +++ b/src/cpp/server/dynamic_thread_pool.cc @@ -19,20 +19,24 @@ #include "src/cpp/server/dynamic_thread_pool.h" #include <mutex> -#include <thread> #include <grpc/support/log.h> +#include "src/core/lib/gprpp/thd.h" + namespace grpc { DynamicThreadPool::DynamicThread::DynamicThread(DynamicThreadPool* pool) : pool_(pool), - thd_(new std::thread(&DynamicThreadPool::DynamicThread::ThreadFunc, - this)) {} -DynamicThreadPool::DynamicThread::~DynamicThread() { - thd_->join(); - thd_.reset(); + thd_("dynamic thread pool thread", + [](void* th) { + reinterpret_cast<DynamicThreadPool::DynamicThread*>(th) + ->ThreadFunc(); + }, + this) { + thd_.Start(); } +DynamicThreadPool::DynamicThread::~DynamicThread() { thd_.Join(); } void DynamicThreadPool::DynamicThread::ThreadFunc() { pool_->ThreadFunc(); diff --git a/src/cpp/server/dynamic_thread_pool.h b/src/cpp/server/dynamic_thread_pool.h index 880a03d0f0..5df8cf2b04 100644 --- a/src/cpp/server/dynamic_thread_pool.h +++ b/src/cpp/server/dynamic_thread_pool.h @@ -24,10 +24,10 @@ #include <memory> #include <mutex> #include <queue> -#include <thread> #include <grpcpp/support/config.h> +#include "src/core/lib/gprpp/thd.h" #include "src/cpp/server/thread_pool_interface.h" namespace grpc { @@ -47,7 +47,7 @@ class DynamicThreadPool final : public ThreadPoolInterface { private: DynamicThreadPool* pool_; - std::unique_ptr<std::thread> thd_; + grpc_core::Thread thd_; void ThreadFunc(); }; std::mutex mu_; diff --git a/src/cpp/thread_manager/thread_manager.cc b/src/cpp/thread_manager/thread_manager.cc index 23264f1b5b..21cc9bbb31 100644 --- a/src/cpp/thread_manager/thread_manager.cc +++ b/src/cpp/thread_manager/thread_manager.cc @@ -20,18 +20,24 @@ #include <climits> #include <mutex> -#include <thread> #include <grpc/support/log.h> +#include "src/core/lib/gprpp/thd.h" + namespace grpc { ThreadManager::WorkerThread::WorkerThread(ThreadManager* thd_mgr) : thd_mgr_(thd_mgr) { // Make thread creation exclusive with respect to its join happening in // ~WorkerThread(). - std::lock_guard<std::mutex> lock(wt_mu_); - thd_ = std::thread(&ThreadManager::WorkerThread::Run, this); + thd_ = grpc_core::Thread( + "sync server thread", + [](void* th) { + reinterpret_cast<ThreadManager::WorkerThread*>(th)->Run(); + }, + this); + thd_.Start(); } void ThreadManager::WorkerThread::Run() { @@ -41,8 +47,7 @@ void ThreadManager::WorkerThread::Run() { ThreadManager::WorkerThread::~WorkerThread() { // Don't join until the thread is fully constructed. - std::lock_guard<std::mutex> lock(wt_mu_); - thd_.join(); + thd_.Join(); } ThreadManager::ThreadManager(int min_pollers, int max_pollers) diff --git a/src/cpp/thread_manager/thread_manager.h b/src/cpp/thread_manager/thread_manager.h index 1113031695..5a40f2de47 100644 --- a/src/cpp/thread_manager/thread_manager.h +++ b/src/cpp/thread_manager/thread_manager.h @@ -23,10 +23,11 @@ #include <list> #include <memory> #include <mutex> -#include <thread> #include <grpcpp/support/config.h> +#include "src/core/lib/gprpp/thd.h" + namespace grpc { class ThreadManager { @@ -84,8 +85,8 @@ class ThreadManager { virtual void Wait(); private: - // Helper wrapper class around std::thread. This takes a ThreadManager object - // and starts a new std::thread to calls the Run() function. + // Helper wrapper class around grpc_core::Thread. Takes a ThreadManager object + // and starts a new grpc_core::Thread to calls the Run() function. // // The Run() function calls ThreadManager::MainWorkLoop() function and once // that completes, it marks the WorkerThread completed by calling @@ -101,8 +102,7 @@ class ThreadManager { void Run(); ThreadManager* const thd_mgr_; - std::mutex wt_mu_; - std::thread thd_; + grpc_core::Thread thd_; }; // The main funtion in ThreadManager |