27 using namespace folly;
31 template <
class ExecutorBase>
32 class GlobalExecutor {
34 explicit GlobalExecutor(
35 Function<std::unique_ptr<ExecutorBase>()> constructDefault)
36 : constructDefault_(
std::
move(constructDefault)) {}
38 std::shared_ptr<ExecutorBase>
get() {
41 if (
auto executor = executor_.lock()) {
47 if (
auto executor = executor_.lock()) {
51 if (!defaultExecutor_) {
52 defaultExecutor_ = constructDefault_();
55 return defaultExecutor_;
58 void set(std::weak_ptr<ExecutorBase>
executor) {
65 std::weak_ptr<ExecutorBase> executor_;
66 std::shared_ptr<ExecutorBase> defaultExecutor_;
71 return new GlobalExecutor<Executor>(
73 [] {
return std::make_unique<InlineExecutor>(); });
77 return new GlobalExecutor<IOExecutor>(
80 return std::make_unique<IOThreadPoolExecutor>(
81 std::thread::hardware_concurrency(),
82 std::make_shared<NamedThreadFactory>(
"GlobalIOThreadPool"));
91 if (
auto singleton = gGlobalCPUExecutor.try_get()) {
98 if (
auto singleton = gGlobalCPUExecutor.try_get()) {
104 if (
auto singleton = gGlobalIOExecutor.try_get()) {
111 if (
auto singleton = gGlobalIOExecutor.try_get()) {
static Singleton< ShutdownSocketSet, PrivateTag > singleton
constexpr detail::Map< Move > move
EventBase * getEventBase()
void setIOExecutor(std::weak_ptr< IOExecutor > executor)
—— Concurrent Priority Queue Implementation ——
PUSHMI_INLINE_VAR constexpr __adl::get_executor_fn executor
GuardImpl guard(ErrorHandler &&handler)
std::shared_ptr< Executor > getCPUExecutor()
void setCPUExecutor(std::weak_ptr< Executor > executor)
std::shared_ptr< IOExecutor > getIOExecutor()