Commit 3b0fb5d6 authored by Fengyang Wang's avatar Fengyang Wang Committed by Facebook Github Bot

Make EventBase subclass IOExecutor (as in docstring)

Summary: EventBase meets the definition of IOExecutor (it is an executor that "manages" at least one EventBase) and is already claimed to be one in the docstring.

Reviewed By: yfeldblum

Differential Revision: D7064481

fbshipit-source-id: 026e0e4c24d6fb15a32bc4772b35689f830ed944
parent b5fcc4f9
...@@ -746,5 +746,9 @@ VirtualEventBase& EventBase::getVirtualEventBase() { ...@@ -746,5 +746,9 @@ VirtualEventBase& EventBase::getVirtualEventBase() {
return *virtualEventBase_; return *virtualEventBase_;
} }
EventBase* EventBase::getEventBase() {
return this;
}
constexpr std::chrono::milliseconds EventBase::SmoothLoopTime::buffer_interval_; constexpr std::chrono::milliseconds EventBase::SmoothLoopTime::buffer_interval_;
} // namespace folly } // namespace folly
...@@ -39,6 +39,7 @@ ...@@ -39,6 +39,7 @@
#include <folly/Portability.h> #include <folly/Portability.h>
#include <folly/ScopeGuard.h> #include <folly/ScopeGuard.h>
#include <folly/executors/DrivableExecutor.h> #include <folly/executors/DrivableExecutor.h>
#include <folly/executors/IOExecutor.h>
#include <folly/executors/SequencedExecutor.h> #include <folly/executors/SequencedExecutor.h>
#include <folly/experimental/ExecutionObserver.h> #include <folly/experimental/ExecutionObserver.h>
#include <folly/io/async/AsyncTimeout.h> #include <folly/io/async/AsyncTimeout.h>
...@@ -128,6 +129,7 @@ class VirtualEventBase; ...@@ -128,6 +129,7 @@ class VirtualEventBase;
class EventBase : private boost::noncopyable, class EventBase : private boost::noncopyable,
public TimeoutManager, public TimeoutManager,
public DrivableExecutor, public DrivableExecutor,
public IOExecutor,
public SequencedExecutor { public SequencedExecutor {
public: public:
using Func = folly::Function<void()>; using Func = folly::Function<void()>;
...@@ -659,6 +661,9 @@ class EventBase : private boost::noncopyable, ...@@ -659,6 +661,9 @@ class EventBase : private boost::noncopyable,
// don't need to manage the life time of the VirtualEventBase used. // don't need to manage the life time of the VirtualEventBase used.
folly::VirtualEventBase& getVirtualEventBase(); folly::VirtualEventBase& getVirtualEventBase();
/// Implements the IOExecutor interface
EventBase* getEventBase() override;
protected: protected:
void keepAliveAcquire() override { void keepAliveAcquire() override {
if (inRunningEventBaseThread()) { if (inRunningEventBaseThread()) {
......
...@@ -1917,6 +1917,13 @@ TEST(EventBaseTest, DrivableExecutorTest) { ...@@ -1917,6 +1917,13 @@ TEST(EventBaseTest, DrivableExecutorTest) {
t.join(); t.join();
} }
TEST(EventBaseTest, IOExecutorTest) {
EventBase base;
// Ensure EventBase manages itself as an IOExecutor.
EXPECT_EQ(base.getEventBase(), &base);
}
TEST(EventBaseTest, RequestContextTest) { TEST(EventBaseTest, RequestContextTest) {
EventBase evb; EventBase evb;
auto defaultCtx = RequestContext::get(); auto defaultCtx = RequestContext::get();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment