Commit bf4793bd authored by Shai Szulanski's avatar Shai Szulanski Committed by Facebook Github Bot

Enable KeepAlive support in ScopedEventBaseThread

Reviewed By: yfeldblum

Differential Revision: D18356211

fbshipit-source-id: ad2361c65260a1a09f8536d07e5447cfcf5cc552
parent 85d753b7
......@@ -132,6 +132,8 @@ class EventBase : public TimeoutManager,
public SequencedExecutor,
public ScheduledExecutor {
public:
friend class ScopedEventBaseThread;
using Func = folly::Function<void()>;
/**
......
......@@ -60,6 +60,15 @@ class ScopedEventBaseThread : public IOExecutor, public SequencedExecutor {
getEventBase()->add(std::move(func));
}
protected:
bool keepAliveAcquire() override {
return getEventBase()->keepAliveAcquire();
}
void keepAliveRelease() override {
getEventBase()->keepAliveRelease();
}
private:
ScopedEventBaseThread(ScopedEventBaseThread&& other) = delete;
ScopedEventBaseThread& operator=(ScopedEventBaseThread&& other) = delete;
......
......@@ -20,6 +20,7 @@
#include <string>
#include <folly/Optional.h>
#include <folly/futures/Promise.h>
#include <folly/io/async/EventBaseManager.h>
#include <folly/portability/GTest.h>
#include <folly/synchronization/Baton.h>
......@@ -87,3 +88,28 @@ TEST_F(ScopedEventBaseThreadTest, eb_dtor_in_io_thread) {
sebt.clear();
EXPECT_EQ(io_thread_id, eb_dtor_thread_id);
}
TEST_F(ScopedEventBaseThreadTest, keepalive) {
Baton<> started, done, reset;
folly::Executor::KeepAlive<> ex;
Promise<Unit> p;
std::thread t1([&] {
ScopedEventBaseThread sebt;
ex = &sebt;
started.post();
});
std::thread t2([&] {
started.wait();
p.getSemiFuture().via(ex).thenValue([&, ex](auto&&) { done.post(); });
ex.reset();
reset.post();
});
reset.wait();
p.setValue();
ASSERT_TRUE(done.try_wait_for(seconds(1)));
t1.join();
t2.join();
}
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