From: James Sedgwick <jsedgwick@fb.com> Date: Mon, 15 Dec 2014 19:43:32 +0000 (-0800) Subject: move wangle/Executor.h to folly/ root X-Git-Tag: v0.22.0~103 X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=973d5f6166c4ab4aed4526fe1b0cfbb9e63c4fc8;p=folly.git move wangle/Executor.h to folly/ root Summary: this removes the dep EventBase has on wangle as we prepare to split off wangle also changes namespace from folly::wangle to folly Test Plan: just a couple of codemods so waiting for contbuild Reviewed By: davejwatson@fb.com Subscribers: trunkagent, fbcode-common-diffs@, chaoyc, search-fbcode-diffs@, zeus-diffs@, nli, cold-storage-diffs@, unicorn-diffs@, targeting-diff-backend@, hannesr, vighnesh, fugalh, alandau, bmatheny, adityab, zhuohuang, luk, darshan, gunjan, hdoshi, dzhulgakov, alihussains, panin, ves, mshneer, folly-diffs@, lins, nimishshah FB internal diff: D1737376 Tasks: 5802833 Signature: t1:1737376:1418423430:82d219c34fcc50218c380a17435e5880e53db6bd --- diff --git a/folly/Executor.h b/folly/Executor.h new file mode 100644 index 00000000..5ba4844b --- /dev/null +++ b/folly/Executor.h @@ -0,0 +1,46 @@ +/* + * Copyright 2014 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. + */ + +#pragma once + +#include <functional> + +namespace folly { + +typedef std::function<void()> Func; + +/// An Executor accepts units of work with add(), which should be +/// threadsafe. +class Executor { + public: + virtual ~Executor() = default; + + /// Enqueue a function to executed by this executor. This and all + /// variants must be threadsafe. + virtual void add(Func) = 0; + + /// A convenience function for shared_ptr to legacy functors. + /// + /// Sometimes you have a functor that is move-only, and therefore can't be + /// converted to a std::function (e.g. std::packaged_task). In that case, + /// wrap it in a shared_ptr (or maybe folly::MoveWrapper) and use this. + template <class P> + void addPtr(P fn) { + this->add([fn]() mutable { (*fn)(); }); + } +}; + +} // folly diff --git a/folly/Makefile.am b/folly/Makefile.am index 4f2d8da7..7f78fa66 100644 --- a/folly/Makefile.am +++ b/folly/Makefile.am @@ -65,6 +65,7 @@ nobase_follyinclude_HEADERS = \ dynamic-inl.h \ Exception.h \ ExceptionWrapper.h \ + Executor.h \ EvictingCacheMap.h \ experimental/Bits.h \ experimental/EliasFanoCoding.h \ @@ -235,7 +236,6 @@ nobase_follyinclude_HEADERS = \ Varint.h \ VersionCheck.h \ wangle/Deprecated.h \ - wangle/Executor.h \ wangle/Future-inl.h \ wangle/Future.h \ wangle/InlineExecutor.h \ diff --git a/folly/experimental/wangle/bootstrap/ServerBootstrap-inl.h b/folly/experimental/wangle/bootstrap/ServerBootstrap-inl.h index 7268e2a7..8db45409 100644 --- a/folly/experimental/wangle/bootstrap/ServerBootstrap-inl.h +++ b/folly/experimental/wangle/bootstrap/ServerBootstrap-inl.h @@ -105,7 +105,7 @@ class ServerWorkerFactory : public folly::wangle::ThreadFactory { std::make_shared<folly::wangle::NamedThreadFactory>("BootstrapWorker")) , acceptorFactory_(acceptorFactory) {} - virtual std::thread newThread(folly::wangle::Func&& func) override; + virtual std::thread newThread(folly::Func&& func) override; void setInternalFactory( std::shared_ptr<folly::wangle::NamedThreadFactory> internalFactory); diff --git a/folly/experimental/wangle/bootstrap/ServerBootstrap.cpp b/folly/experimental/wangle/bootstrap/ServerBootstrap.cpp index 594e9604..7a75452b 100644 --- a/folly/experimental/wangle/bootstrap/ServerBootstrap.cpp +++ b/folly/experimental/wangle/bootstrap/ServerBootstrap.cpp @@ -20,7 +20,7 @@ namespace folly { std::thread ServerWorkerFactory::newThread( - folly::wangle::Func&& func) { + folly::Func&& func) { auto id = nextWorkerId_++; auto worker = acceptorFactory_->newAcceptor(); { diff --git a/folly/experimental/wangle/concurrent/ThreadFactory.h b/folly/experimental/wangle/concurrent/ThreadFactory.h index 8f799065..7654fbc9 100644 --- a/folly/experimental/wangle/concurrent/ThreadFactory.h +++ b/folly/experimental/wangle/concurrent/ThreadFactory.h @@ -15,7 +15,7 @@ */ #pragma once -#include <folly/wangle/Executor.h> +#include <folly/Executor.h> #include <thread> diff --git a/folly/experimental/wangle/concurrent/ThreadPoolExecutor.h b/folly/experimental/wangle/concurrent/ThreadPoolExecutor.h index b6b0dd78..451f164f 100644 --- a/folly/experimental/wangle/concurrent/ThreadPoolExecutor.h +++ b/folly/experimental/wangle/concurrent/ThreadPoolExecutor.h @@ -15,7 +15,7 @@ */ #pragma once -#include <folly/wangle/Executor.h> +#include <folly/Executor.h> #include <folly/experimental/wangle/concurrent/LifoSemMPMCQueue.h> #include <folly/experimental/wangle/concurrent/NamedThreadFactory.h> #include <folly/experimental/wangle/rx/Observable.h> diff --git a/folly/experimental/wangle/concurrent/test/ThreadPoolExecutorTest.cpp b/folly/experimental/wangle/concurrent/test/ThreadPoolExecutorTest.cpp index 2749d0cd..9898d40e 100644 --- a/folly/experimental/wangle/concurrent/test/ThreadPoolExecutorTest.cpp +++ b/folly/experimental/wangle/concurrent/test/ThreadPoolExecutorTest.cpp @@ -24,7 +24,7 @@ using namespace folly::wangle; using namespace std::chrono; -static Func burnMs(uint64_t ms) { +static folly::Func burnMs(uint64_t ms) { return [ms]() { std::this_thread::sleep_for(milliseconds(ms)); }; } diff --git a/folly/experimental/wangle/rx/Observable.h b/folly/experimental/wangle/rx/Observable.h index 7a914696..e9a6196e 100644 --- a/folly/experimental/wangle/rx/Observable.h +++ b/folly/experimental/wangle/rx/Observable.h @@ -24,7 +24,7 @@ #include <folly/SmallLocks.h> #include <folly/ThreadLocal.h> #include <folly/small_vector.h> -#include <folly/wangle/Executor.h> +#include <folly/Executor.h> #include <map> #include <memory> diff --git a/folly/experimental/wangle/rx/types.h b/folly/experimental/wangle/rx/types.h index 0f10c1cb..27c2f3b7 100644 --- a/folly/experimental/wangle/rx/types.h +++ b/folly/experimental/wangle/rx/types.h @@ -17,13 +17,13 @@ #pragma once #include <folly/ExceptionWrapper.h> -#include <folly/wangle/Executor.h> +#include <folly/Executor.h> namespace folly { namespace wangle { typedef folly::exception_wrapper Error; - // The wangle::Executor is basically an rx Scheduler (by design). So just + // The Executor is basically an rx Scheduler (by design). So just // alias it. - typedef std::shared_ptr<folly::wangle::Executor> SchedulerPtr; + typedef std::shared_ptr<folly::Executor> SchedulerPtr; template <class T, size_t InlineObservers = 3> struct Observable; template <class T> struct Observer; diff --git a/folly/io/async/EventBase.h b/folly/io/async/EventBase.h index ec4a6ad6..109da17c 100644 --- a/folly/io/async/EventBase.h +++ b/folly/io/async/EventBase.h @@ -20,7 +20,7 @@ #include <folly/io/async/AsyncTimeout.h> #include <folly/io/async/TimeoutManager.h> #include <folly/io/async/Request.h> -#include <folly/wangle/Executor.h> +#include <folly/Executor.h> #include <memory> #include <stack> #include <list> @@ -96,7 +96,7 @@ class RequestEventBase : public RequestData { * another thread it is explicitly listed in the method comments. */ class EventBase : - private boost::noncopyable, public TimeoutManager, public wangle::Executor + private boost::noncopyable, public TimeoutManager, public Executor { public: /** @@ -478,7 +478,7 @@ class EventBase : */ const std::string& getName(); - /// Implements the wangle::Executor interface + /// Implements the Executor interface void add(Cob fn) override { // runInEventBaseThread() takes a const&, // so no point in doing std::move here. diff --git a/folly/wangle/Executor.h b/folly/wangle/Executor.h deleted file mode 100644 index bd720f60..00000000 --- a/folly/wangle/Executor.h +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright 2014 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. - */ - -#pragma once - -#include <functional> - -namespace folly { namespace wangle { - -typedef std::function<void()> Func; - -/// An Executor accepts units of work with add(), which should be -/// threadsafe. -class Executor { - public: - virtual ~Executor() = default; - - /// Enqueue a function to executed by this executor. This and all - /// variants must be threadsafe. - virtual void add(Func) = 0; - - /// A convenience function for shared_ptr to legacy functors. - /// - /// Sometimes you have a functor that is move-only, and therefore can't be - /// converted to a std::function (e.g. std::packaged_task). In that case, - /// wrap it in a shared_ptr (or maybe folly::MoveWrapper) and use this. - template <class P> - void addPtr(P fn) { - this->add([fn]() mutable { (*fn)(); }); - } -}; - -}} // folly::wangle diff --git a/folly/wangle/InlineExecutor.h b/folly/wangle/InlineExecutor.h index df9bfe29..e6924085 100644 --- a/folly/wangle/InlineExecutor.h +++ b/folly/wangle/InlineExecutor.h @@ -15,7 +15,7 @@ */ #pragma once -#include <folly/wangle/Executor.h> +#include <folly/Executor.h> namespace folly { namespace wangle { diff --git a/folly/wangle/QueuedImmediateExecutor.h b/folly/wangle/QueuedImmediateExecutor.h index a4c4985d..a82c32db 100644 --- a/folly/wangle/QueuedImmediateExecutor.h +++ b/folly/wangle/QueuedImmediateExecutor.h @@ -16,7 +16,7 @@ #pragma once -#include <folly/wangle/Executor.h> +#include <folly/Executor.h> namespace folly { namespace wangle { diff --git a/folly/wangle/ScheduledExecutor.h b/folly/wangle/ScheduledExecutor.h index fe5f6f12..94850c28 100644 --- a/folly/wangle/ScheduledExecutor.h +++ b/folly/wangle/ScheduledExecutor.h @@ -16,7 +16,7 @@ #pragma once -#include <folly/wangle/Executor.h> +#include <folly/Executor.h> #include <chrono> #include <memory> #include <stdexcept> diff --git a/folly/wangle/detail/Core.h b/folly/wangle/detail/Core.h index 03d09b74..933cd7ad 100644 --- a/folly/wangle/detail/Core.h +++ b/folly/wangle/detail/Core.h @@ -27,7 +27,7 @@ #include <folly/wangle/Try.h> #include <folly/wangle/Promise.h> #include <folly/wangle/Future.h> -#include <folly/wangle/Executor.h> +#include <folly/Executor.h> #include <folly/wangle/detail/FSM.h> #include <folly/io/async/Request.h> diff --git a/folly/wangle/test/FutureTest.cpp b/folly/wangle/test/FutureTest.cpp index a068dc01..d6cfbfbc 100644 --- a/folly/wangle/test/FutureTest.cpp +++ b/folly/wangle/test/FutureTest.cpp @@ -24,7 +24,7 @@ #include <type_traits> #include <unistd.h> #include <folly/Memory.h> -#include <folly/wangle/Executor.h> +#include <folly/Executor.h> #include <folly/wangle/Future.h> #include <folly/wangle/ManualExecutor.h> #include <folly/MPMCQueue.h> diff --git a/folly/wangle/test/Thens.cpp b/folly/wangle/test/Thens.cpp index f990678d..e8ac875d 100644 --- a/folly/wangle/test/Thens.cpp +++ b/folly/wangle/test/Thens.cpp @@ -7,7 +7,7 @@ TEST(Future, thenVariants) { SomeClass anObject; - Executor* anExecutor; + folly::Executor* anExecutor; {Future<B> f = someFuture<A>().then(&aFunction<Future<B>, Try<A>&&>);} {Future<B> f = someFuture<A>().then(&SomeClass::aStaticMethod<Future<B>, Try<A>&&>);} diff --git a/folly/wangle/test/Thens.h b/folly/wangle/test/Thens.h index 995ff848..928f8205 100644 --- a/folly/wangle/test/Thens.h +++ b/folly/wangle/test/Thens.h @@ -18,7 +18,7 @@ #include <gtest/gtest.h> #include <memory> #include <folly/wangle/Future.h> -#include <folly/wangle/Executor.h> +#include <folly/Executor.h> using namespace folly::wangle; using namespace std; diff --git a/folly/wangle/test/thens.rb b/folly/wangle/test/thens.rb index 9c753725..61ca26de 100755 --- a/folly/wangle/test/thens.rb +++ b/folly/wangle/test/thens.rb @@ -70,7 +70,7 @@ print <<EOF TEST(Future, thenVariants) { SomeClass anObject; - Executor* anExecutor; + folly::Executor* anExecutor; #{tests.join("\n ")} }