From 9917cdab81a12f1a06dbefc811f782d1cf76c7e3 Mon Sep 17 00:00:00 2001 From: Yedidya Feldblum Date: Tue, 17 Oct 2017 13:09:48 -0700 Subject: [PATCH] An InlineExecutor singleton Summary: [Folly] An `InlineExecutor` singleton. Using the Leaky Meyers Singleton pattern, so that it is always available whenever required. Differential Revision: D6074534 fbshipit-source-id: bd4c9cd6a1e60c80de5d2eef1cb6a1e7f16b4e50 --- folly/futures/InlineExecutor.cpp | 28 ++++++++++++++++++++++++++++ folly/futures/InlineExecutor.h | 22 ++++++++++++---------- 2 files changed, 40 insertions(+), 10 deletions(-) create mode 100644 folly/futures/InlineExecutor.cpp diff --git a/folly/futures/InlineExecutor.cpp b/folly/futures/InlineExecutor.cpp new file mode 100644 index 00000000..848e7f26 --- /dev/null +++ b/folly/futures/InlineExecutor.cpp @@ -0,0 +1,28 @@ +/* + * Copyright 2017 Facebook, Inc. + * + * 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 + +#include + +namespace folly { + +InlineExecutor& InlineExecutor::instance() { + static auto instance = Indestructible{}; + return *instance; +} + +} // namespace folly diff --git a/folly/futures/InlineExecutor.h b/folly/futures/InlineExecutor.h index 5f1ae691..644ff7bf 100644 --- a/folly/futures/InlineExecutor.h +++ b/folly/futures/InlineExecutor.h @@ -19,14 +19,16 @@ namespace folly { - /// When work is "queued", execute it immediately inline. - /// Usually when you think you want this, you actually want a - /// QueuedImmediateExecutor. - class InlineExecutor : public Executor { - public: - void add(Func f) override { - f(); - } - }; +/// When work is "queued", execute it immediately inline. +/// Usually when you think you want this, you actually want a +/// QueuedImmediateExecutor. +class InlineExecutor : public Executor { + public: + static InlineExecutor& instance(); -} + void add(Func f) override { + f(); + } +}; + +} // namespace folly -- 2.34.1