blob: 8ca3e32c2fb19305f2eb51907adb1aaec360a5ea [file] [log] [blame]
Yang Gao6f4fb3b2015-06-03 12:56:19 -07001/*
2 *
Jan Tattermusch7897ae92017-06-07 22:57:36 +02003 * Copyright 2015 gRPC authors.
Yang Gao6f4fb3b2015-06-03 12:56:19 -07004 *
Jan Tattermusch7897ae92017-06-07 22:57:36 +02005 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
Yang Gao6f4fb3b2015-06-03 12:56:19 -07008 *
Jan Tattermusch7897ae92017-06-07 22:57:36 +02009 * http://www.apache.org/licenses/LICENSE-2.0
Yang Gao6f4fb3b2015-06-03 12:56:19 -070010 *
Jan Tattermusch7897ae92017-06-07 22:57:36 +020011 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
Yang Gao6f4fb3b2015-06-03 12:56:19 -070016 *
17 */
18
19#include <grpc/support/cpu.h>
yang-g3e4bd952015-08-24 15:54:07 -070020
Vijay Paie8a7e302015-08-24 10:52:33 -070021#include "src/cpp/server/dynamic_thread_pool.h"
Yang Gao6f4fb3b2015-06-03 12:56:19 -070022
23#ifndef GRPC_CUSTOM_DEFAULT_THREAD_POOL
24
25namespace grpc {
ncteiseneb70b9e2017-07-06 09:38:26 -070026namespace {
Yang Gao6f4fb3b2015-06-03 12:56:19 -070027
ncteiseneb70b9e2017-07-06 09:38:26 -070028ThreadPoolInterface* CreateDefaultThreadPoolImpl() {
Craig Tillerd6c98df2015-08-18 09:33:44 -070029 int cores = gpr_cpu_num_cores();
30 if (!cores) cores = 4;
31 return new DynamicThreadPool(cores);
Yang Gao6f4fb3b2015-06-03 12:56:19 -070032}
33
ncteiseneb70b9e2017-07-06 09:38:26 -070034CreateThreadPoolFunc g_ctp_impl = CreateDefaultThreadPoolImpl;
35
36} // namespace
ncteisen30939f82017-07-05 15:43:18 -070037
ncteisena5d557b2017-07-05 15:52:28 -070038ThreadPoolInterface* CreateDefaultThreadPool() { return g_ctp_impl(); }
ncteisen30939f82017-07-05 15:43:18 -070039
ncteisena5d557b2017-07-05 15:52:28 -070040void SetCreateThreadPool(CreateThreadPoolFunc func) { g_ctp_impl = func; }
ncteisen30939f82017-07-05 15:43:18 -070041
Yang Gao6f4fb3b2015-06-03 12:56:19 -070042} // namespace grpc
43
44#endif // !GRPC_CUSTOM_DEFAULT_THREAD_POOL