From: James Sedgwick Date: Wed, 18 Oct 2017 16:44:09 +0000 (-0700) Subject: move futures/DrivableExecutor to executors/DrivableExecutor X-Git-Tag: v2017.10.23.00~28 X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=dca6f3ea44d8fb0aaa1d4ae6761694b4ae9d0965;p=folly.git move futures/DrivableExecutor to executors/DrivableExecutor Summary: as title Reviewed By: yfeldblum Differential Revision: D6062437 fbshipit-source-id: 4f99e779e280fdb0b1f035013caff18764e86ab5 --- diff --git a/folly/Makefile.am b/folly/Makefile.am index 94b417c2..7159baea 100644 --- a/folly/Makefile.am +++ b/folly/Makefile.am @@ -88,6 +88,7 @@ nobase_follyinclude_HEADERS = \ executors/BlockingQueue.h \ executors/CPUThreadPoolExecutor.h \ executors/Codel.h \ + executors/DrivableExecutor.h \ executors/FiberIOExecutor.h \ executors/FutureExecutor.h \ executors/GlobalExecutor.h \ @@ -205,7 +206,6 @@ nobase_follyinclude_HEADERS = \ Format-inl.h \ functional/Invoke.h \ futures/Barrier.h \ - futures/DrivableExecutor.h \ futures/Future-pre.h \ futures/helpers.h \ futures/Future.h \ diff --git a/folly/executors/DrivableExecutor.h b/folly/executors/DrivableExecutor.h new file mode 100644 index 00000000..9f9b61e3 --- /dev/null +++ b/folly/executors/DrivableExecutor.h @@ -0,0 +1,55 @@ +/* + * 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. + */ + +#pragma once + +#include + +namespace folly { + +/* + * A DrivableExecutor can be driven via its drive() method + * Examples include EventBase (via loopOnce()) and ManualExecutor + * (via makeProgress()). + * + * This interface is most handy in conjunction with + * Future::getVia(DrivableExecutor*) and + * Future::waitVia(DrivableExecutor*) + * + * These call drive() * repeatedly until the Future is fulfilled. + * getVia() returns the value (or throws the exception) and waitVia() returns + * the same Future for chainability. + * + * These will be most helpful in tests, for instance if you need to pump a mock + * EventBase until Futures complete. + */ + +class DrivableExecutor : public virtual Executor { + public: + ~DrivableExecutor() override = default; + + // Make progress on this Executor's work. + // + // Drive *must not* busy wait if there is no work to do. Instead, + // sleep (using a semaphore or similar) until at least one event is + // processed. + // I.e. make_future().via(foo).then(...).getVia(DrivableExecutor) + // must not spin, even though nothing happens on the drivable + // executor. + virtual void drive() = 0; +}; + +} // namespace folly diff --git a/folly/executors/NotificationQueueExecutor.h b/folly/executors/NotificationQueueExecutor.h index 3738be24..5e19fc41 100644 --- a/folly/executors/NotificationQueueExecutor.h +++ b/folly/executors/NotificationQueueExecutor.h @@ -17,7 +17,7 @@ #include #include -#include +#include #include namespace folly { diff --git a/folly/futures/DrivableExecutor.h b/folly/futures/DrivableExecutor.h deleted file mode 100644 index 9f9b61e3..00000000 --- a/folly/futures/DrivableExecutor.h +++ /dev/null @@ -1,55 +0,0 @@ -/* - * 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. - */ - -#pragma once - -#include - -namespace folly { - -/* - * A DrivableExecutor can be driven via its drive() method - * Examples include EventBase (via loopOnce()) and ManualExecutor - * (via makeProgress()). - * - * This interface is most handy in conjunction with - * Future::getVia(DrivableExecutor*) and - * Future::waitVia(DrivableExecutor*) - * - * These call drive() * repeatedly until the Future is fulfilled. - * getVia() returns the value (or throws the exception) and waitVia() returns - * the same Future for chainability. - * - * These will be most helpful in tests, for instance if you need to pump a mock - * EventBase until Futures complete. - */ - -class DrivableExecutor : public virtual Executor { - public: - ~DrivableExecutor() override = default; - - // Make progress on this Executor's work. - // - // Drive *must not* busy wait if there is no work to do. Instead, - // sleep (using a semaphore or similar) until at least one event is - // processed. - // I.e. make_future().via(foo).then(...).getVia(DrivableExecutor) - // must not spin, even though nothing happens on the drivable - // executor. - virtual void drive() = 0; -}; - -} // namespace folly diff --git a/folly/futures/Future.h b/folly/futures/Future.h index f5c3190f..0c4092aa 100644 --- a/folly/futures/Future.h +++ b/folly/futures/Future.h @@ -27,7 +27,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/folly/futures/ManualExecutor.h b/folly/futures/ManualExecutor.h index 689111eb..373e4ac7 100644 --- a/folly/futures/ManualExecutor.h +++ b/folly/futures/ManualExecutor.h @@ -22,7 +22,7 @@ #include #include -#include +#include #include namespace folly { diff --git a/folly/futures/README.md b/folly/futures/README.md index d0e2693d..e4bce679 100644 --- a/folly/futures/README.md +++ b/folly/futures/README.md @@ -902,7 +902,7 @@ Although inspired by the C++11 std::future interface, it is not a drop-in replac

getVia() and waitVia() #

-

T Future<T>::getVia(DrivableExecutor*) and Future<T> Future<T>::waitVia(DrivableExecutor*) have the same semantics as get() and wait() except that they drive some Executor until the Future is complete. DrivableExecutor is a simple subinterface of Executor that requires the presence of a method drive() which can somehow make progress on the Executor's work. Two commonly helpful implementations are EventBase (where drive() loops on the EventBase) and ManualExecutor. These are simple but useful sugar for the following common pattern:

+

T Future<T>::getVia(DrivableExecutor*) and Future<T> Future<T>::waitVia(DrivableExecutor*) have the same semantics as get() and wait() except that they drive some Executor until the Future is complete. DrivableExecutor is a simple subinterface of Executor that requires the presence of a method drive() which can somehow make progress on the Executor's work. Two commonly helpful implementations are EventBase (where drive() loops on the EventBase) and ManualExecutor. These are simple but useful sugar for the following common pattern:

Given this:

diff --git a/folly/futures/test/ViaTest.cpp b/folly/futures/test/ViaTest.cpp index 198c4f93..1a530d37 100644 --- a/folly/futures/test/ViaTest.cpp +++ b/folly/futures/test/ViaTest.cpp @@ -18,7 +18,7 @@ #include #include -#include +#include #include #include #include diff --git a/folly/io/async/EventBase.h b/folly/io/async/EventBase.h index ee7ceca7..670d6af6 100644 --- a/folly/io/async/EventBase.h +++ b/folly/io/async/EventBase.h @@ -40,15 +40,14 @@ #include #include #include +#include #include -#include #include #include #include #include #include - namespace folly { using Cob = Func; // defined in folly/Executor.h