Skip to content
Snippets Groups Projects
Commit 50791829 authored by Noah Eisen's avatar Noah Eisen Committed by GitHub
Browse files

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

Make CreateThreadPool Settable
parents 37e06cfc eb70b9e0
No related branches found
No related tags found
No related merge requests found
......@@ -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
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment