Merge pull request #11693 from ncteisen/refactor-thread-pool

Make CreateThreadPool Settable
pull/11733/head
Noah Eisen 8 years ago committed by GitHub
commit 5079182938
  1. 11
      src/cpp/server/create_default_thread_pool.cc
  2. 4
      src/cpp/server/thread_pool_interface.h

@ -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

@ -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

Loading…
Cancel
Save