Have EventBase implement wangle::Executor
authorHans Fugal <fugalh@fb.com>
Wed, 12 Nov 2014 18:01:50 +0000 (10:01 -0800)
committerDave Watson <davejwatson@fb.com>
Wed, 19 Nov 2014 20:52:20 +0000 (12:52 -0800)
Summary:
It already does the work (`runInEventBaseThread`) but it will now be convenient to pass an `EventBase` where wangle wants an `Executor`.

Had to rip off the `boost::noncopyable` from `wangle::Executor` which is an interface and does not require non-copyability so that didn't really belong there in the first place I think. (Without this change, you get an obscure compiler error because of the double-inheritance from `boost::noncopyable`).

Test Plan: Things build, tests pass

Reviewed By: davejwatson@fb.com

Subscribers: jsedgwick, trunkagent, fugalh, exa, njormrod, folly-diffs@, andrii

FB internal diff: D1671500

Signature: t1:1671500:1415727572:a7dba33c669ca122aecaee3c700f9e53e54838d1

folly/io/async/EventBase.h
folly/wangle/Executor.h

index 98d5769c7a7979836f2474af36000dab50c3d461..3da2169d88cbd5b38baffa843c57f4495ebef1b1 100644 (file)
@@ -19,6 +19,7 @@
 #include <glog/logging.h>
 #include <folly/io/async/AsyncTimeout.h>
 #include <folly/io/async/TimeoutManager.h>
+#include <folly/wangle/Executor.h>
 #include <memory>
 #include <stack>
 #include <list>
@@ -68,7 +69,9 @@ class EventBaseObserver {
  * EventBase from other threads.  When it is safe to call a method from
  * another thread it is explicitly listed in the method comments.
  */
-class EventBase : private boost::noncopyable, public TimeoutManager {
+class EventBase :
+  private boost::noncopyable, public TimeoutManager, public wangle::Executor
+{
  public:
   /**
    * A callback interface to use with runInLoop()
@@ -447,6 +450,13 @@ class EventBase : private boost::noncopyable, public TimeoutManager {
    */
   const std::string& getName();
 
+  /// Implements the wangle::Executor interface
+  void add(Cob fn) override {
+    // runInEventBaseThread() takes a const&,
+    // so no point in doing std::move here.
+    runInEventBaseThread(fn);
+  }
+
  private:
 
   // TimeoutManager
index cc9ce34db37e3ff56ba817cae5dbe9a21597535d..b7c31fb7a04272a322f5dfe8a56713b1c2e150dc 100644 (file)
@@ -24,7 +24,7 @@ namespace folly { namespace wangle {
 
   /// An Executor accepts units of work with add(), which should be
   /// threadsafe.
-  class Executor : boost::noncopyable {
+  class Executor {
    public:
     virtual ~Executor() = default;