Re-sync with internal repository
[hiphop-php.git] / third-party / folly / src / folly / synchronization / HazptrThreadPoolExecutor.cpp
blob1d43e4505062a5e344bbc45de6e05dcc851db65e
1 /*
2 * Copyright (c) Meta Platforms, Inc. and affiliates.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 #include <folly/synchronization/HazptrThreadPoolExecutor.h>
19 #include <folly/Singleton.h>
20 #include <folly/executors/CPUThreadPoolExecutor.h>
22 namespace {
24 struct HazptrTPETag {};
25 folly::Singleton<folly::CPUThreadPoolExecutor, HazptrTPETag> hazptr_tpe_([] {
26 return new folly::CPUThreadPoolExecutor(
27 std::make_pair(1, 1),
28 std::make_shared<folly::NamedThreadFactory>("hazptr-tpe-"));
29 });
31 folly::Executor* get_hazptr_tpe() {
32 auto ex = hazptr_tpe_.try_get();
33 return ex ? ex.get() : nullptr;
36 } // namespace
38 namespace folly {
40 void enable_hazptr_thread_pool_executor() {
41 if (hazptr_use_executor()) {
42 default_hazptr_domain().set_executor(&get_hazptr_tpe);
46 } // namespace folly