Commit d895d4ba authored by Maged Michael's avatar Maged Michael Committed by Facebook Github Bot

hazptr: Add singleton CPUThreadPoolExecutor for default domain asynchronous reclamation

Summary: Add function to make the default hazptr domain use a CPUThreadPoolExecutor.

Reviewed By: davidtgoldblatt

Differential Revision: D19107084

fbshipit-source-id: 873779d7b9314e5920f2542ef23bb707b47a4e10
parent 70953110
/*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <folly/synchronization/HazptrThreadPoolExecutor.h>
#include <folly/Singleton.h>
#include <folly/executors/CPUThreadPoolExecutor.h>
namespace {
struct HazptrTPETag {};
folly::Singleton<folly::CPUThreadPoolExecutor, HazptrTPETag> hazptr_tpe_([] {
return new folly::CPUThreadPoolExecutor(1);
});
folly::Executor* get_hazptr_tpe() {
auto ex = hazptr_tpe_.try_get();
return ex ? ex.get() : nullptr;
}
} // namespace
namespace folly {
void start_hazptr_thread_pool_executor() {
if (FLAGS_folly_hazptr_use_executor) {
default_hazptr_domain().set_executor(&get_hazptr_tpe);
}
}
} // namespace folly
/*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#pragma once
#include <folly/synchronization/Hazptr.h>
namespace folly {
void start_hazptr_thread_pool_executor();
} // namespace folly
...@@ -21,9 +21,9 @@ ...@@ -21,9 +21,9 @@
#include <folly/synchronization/test/Barrier.h> #include <folly/synchronization/test/Barrier.h>
#include <folly/Singleton.h> #include <folly/Singleton.h>
#include <folly/executors/CPUThreadPoolExecutor.h>
#include <folly/portability/GFlags.h> #include <folly/portability/GFlags.h>
#include <folly/portability/GTest.h> #include <folly/portability/GTest.h>
#include <folly/synchronization/HazptrThreadPoolExecutor.h>
#include <folly/test/DeterministicSchedule.h> #include <folly/test/DeterministicSchedule.h>
#include <atomic> #include <atomic>
...@@ -899,18 +899,8 @@ void recursive_destruction_test() { ...@@ -899,18 +899,8 @@ void recursive_destruction_test() {
ASSERT_EQ(c_.dtors(), total); ASSERT_EQ(c_.dtors(), total);
} }
struct TPETag {};
folly::Singleton<folly::CPUThreadPoolExecutor, TPETag> cputpe_([] {
return new folly::CPUThreadPoolExecutor(1);
});
folly::Executor* get_cputpe() {
auto ex = cputpe_.try_get();
return ex ? ex.get() : nullptr;
}
void fork_test() { void fork_test() {
folly::default_hazptr_domain().set_executor(&get_cputpe); folly::start_hazptr_thread_pool_executor();
auto trigger_reclamation = [] { auto trigger_reclamation = [] {
hazptr_obj_batch b; hazptr_obj_batch b;
for (int i = 0; i < 2001; ++i) { for (int i = 0; i < 2001; ++i) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment