Change ThreadManager interface to Executor
authorDave Watson <davejwatson@fb.com>
Thu, 23 Apr 2015 17:03:51 +0000 (10:03 -0700)
committerAlecs King <int@fb.com>
Mon, 27 Apr 2015 23:53:09 +0000 (16:53 -0700)
Summary:
Change ThreadManager interface to more generic Executor interface.  Specific example of supporting fibers.  This diff would replace D1967655

Test Plan: added several unittests

Reviewed By: alandau@fb.com

Subscribers: doug, alandau, bmatheny, mshneer, folly-diffs@, jsedgwick, yfeldblum, chalfant, alikhtarov, andrii, yitingli

FB internal diff: D1994663

Signature: t1:1994663:1429640509:d729ce6f020563b680d1d549f9aa273c739eb925

folly/experimental/fibers/FiberManager.h

index fa4e14aaf26068d7d7db518b889f3870a8db043c..8ce9fc3422ae66a75d9af4d3232831c9721488a8 100644 (file)
@@ -24,6 +24,7 @@
 #include <vector>
 
 #include <folly/AtomicLinkedList.h>
+#include <folly/Executor.h>
 #include <folly/Likely.h>
 #include <folly/IntrusiveList.h>
 #include <folly/futures/Try.h>
@@ -57,7 +58,7 @@ class LocalType {
  * call. This will pause execution of this task and it will be resumed only
  * when it is unblocked (via setData()).
  */
-class FiberManager {
+class FiberManager : public ::folly::Executor {
  public:
   struct Options {
 #ifdef FOLLY_SANITIZE_ADDRESS
@@ -170,6 +171,11 @@ class FiberManager {
   template <typename F>
   void addTaskRemote(F&& func);
 
+  // Executor interface calls addTaskRemote
+  void add(std::function<void()> f) {
+    addTaskRemote(std::move(f));
+  }
+
   /**
    * Add a new task. When the task is complete, execute finally(Try<Result>&&)
    * on the main context.