diff options
author | Noah Eisen <ncteisen@gmail.com> | 2017-07-21 09:27:00 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-07-21 09:27:00 -0700 |
commit | 50791829380e47a04ee8dda9ef23c8288d8646c0 (patch) | |
tree | 910b4e47486a6aee1854a859b877ca05bda869fc /src | |
parent | 37e06cfc4d7e6473b000d4b64c7305da8e98e456 (diff) | |
parent | eb70b9e0df3b51db4e2d3466607e7713425dfac7 (diff) |
Merge pull request #11693 from ncteisen/refactor-thread-pool
Make CreateThreadPool Settable
Diffstat (limited to 'src')
-rw-r--r-- | src/cpp/server/create_default_thread_pool.cc | 11 | ||||
-rw-r--r-- | src/cpp/server/thread_pool_interface.h | 4 |
2 files changed, 14 insertions, 1 deletions
diff --git a/src/cpp/server/create_default_thread_pool.cc b/src/cpp/server/create_default_thread_pool.cc index 17ad331c9c..8ca3e32c2f 100644 --- a/src/cpp/server/create_default_thread_pool.cc +++ b/src/cpp/server/create_default_thread_pool.cc @@ -23,13 +23,22 @@ #ifndef GRPC_CUSTOM_DEFAULT_THREAD_POOL namespace grpc { +namespace { -ThreadPoolInterface* CreateDefaultThreadPool() { +ThreadPoolInterface* CreateDefaultThreadPoolImpl() { int cores = gpr_cpu_num_cores(); if (!cores) cores = 4; return new DynamicThreadPool(cores); } +CreateThreadPoolFunc g_ctp_impl = CreateDefaultThreadPoolImpl; + +} // namespace + +ThreadPoolInterface* CreateDefaultThreadPool() { return g_ctp_impl(); } + +void SetCreateThreadPool(CreateThreadPoolFunc func) { g_ctp_impl = func; } + } // namespace grpc #endif // !GRPC_CUSTOM_DEFAULT_THREAD_POOL diff --git a/src/cpp/server/thread_pool_interface.h b/src/cpp/server/thread_pool_interface.h index 4f4fc7eaaa..028842a776 100644 --- a/src/cpp/server/thread_pool_interface.h +++ b/src/cpp/server/thread_pool_interface.h @@ -32,6 +32,10 @@ class ThreadPoolInterface { virtual void Add(const std::function<void()>& callback) = 0; }; +// Allows different codebases to use their own thread pool impls +typedef ThreadPoolInterface* (*CreateThreadPoolFunc)(void); +void SetCreateThreadPool(CreateThreadPoolFunc func); + ThreadPoolInterface* CreateDefaultThreadPool(); } // namespace grpc |