Commit 6f3b7616 authored by Yedidya Feldblum's avatar Yedidya Feldblum Committed by Facebook Github Bot

Let keep-alive tokens be destroyed from any thread

Summary: [Folly] Let keep-alive tokens be destroyed from any thread.

Reviewed By: andriigrynenko

Differential Revision: D5951397

fbshipit-source-id: 91e72588de4ef33a730ebef5770e77635d4e93ba
parent d6fe55fe
...@@ -81,8 +81,7 @@ class Executor { ...@@ -81,8 +81,7 @@ class Executor {
}; };
/// Returns a keep-alive token which guarantees that Executor will keep /// Returns a keep-alive token which guarantees that Executor will keep
/// processing tasks until the token is released. keep-alive token can only /// processing tasks until the token is released.
/// be destroyed from within the task, scheduled to be run on an executor.
/// ///
/// If executor does not support keep-alive functionality - dummy token will /// If executor does not support keep-alive functionality - dummy token will
/// be returned. /// be returned.
......
...@@ -604,8 +604,6 @@ class EventBase : private boost::noncopyable, ...@@ -604,8 +604,6 @@ class EventBase : private boost::noncopyable,
/// Implements the DrivableExecutor interface /// Implements the DrivableExecutor interface
void drive() override { void drive() override {
// We can't use loopKeepAlive() here since LoopKeepAlive token can only be
// released inside a loop.
++loopKeepAliveCount_; ++loopKeepAliveCount_;
SCOPE_EXIT { SCOPE_EXIT {
--loopKeepAliveCount_; --loopKeepAliveCount_;
...@@ -615,8 +613,7 @@ class EventBase : private boost::noncopyable, ...@@ -615,8 +613,7 @@ class EventBase : private boost::noncopyable,
/// Returns you a handle which make loop() behave like loopForever() until /// Returns you a handle which make loop() behave like loopForever() until
/// destroyed. loop() will return to its original behavior only when all /// destroyed. loop() will return to its original behavior only when all
/// loop keep-alives are released. Loop holder is safe to release only from /// loop keep-alives are released.
/// EventBase thread.
KeepAlive getKeepAliveToken() override { KeepAlive getKeepAliveToken() override {
if (inRunningEventBaseThread()) { if (inRunningEventBaseThread()) {
loopKeepAliveCount_++; loopKeepAliveCount_++;
...@@ -653,8 +650,11 @@ class EventBase : private boost::noncopyable, ...@@ -653,8 +650,11 @@ class EventBase : private boost::noncopyable,
protected: protected:
void keepAliveRelease() override { void keepAliveRelease() override {
dcheckIsInEventBaseThread(); if (inRunningEventBaseThread()) {
loopKeepAliveCount_--; loopKeepAliveCount_--;
} else {
add([=] { loopKeepAliveCount_--; });
}
} }
private: private:
......
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