};
/// Returns a keep-alive token which guarantees that Executor will keep
- /// processing tasks until the token is released. keep-alive token can only
- /// be destroyed from within the task, scheduled to be run on an executor.
+ /// processing tasks until the token is released.
///
/// If executor does not support keep-alive functionality - dummy token will
/// be returned.
/// Implements the DrivableExecutor interface
void drive() override {
- // We can't use loopKeepAlive() here since LoopKeepAlive token can only be
- // released inside a loop.
++loopKeepAliveCount_;
SCOPE_EXIT {
--loopKeepAliveCount_;
/// Returns you a handle which make loop() behave like loopForever() until
/// destroyed. loop() will return to its original behavior only when all
- /// loop keep-alives are released. Loop holder is safe to release only from
- /// EventBase thread.
+ /// loop keep-alives are released.
KeepAlive getKeepAliveToken() override {
if (inRunningEventBaseThread()) {
loopKeepAliveCount_++;
protected:
void keepAliveRelease() override {
- dcheckIsInEventBaseThread();
- loopKeepAliveCount_--;
+ if (inRunningEventBaseThread()) {
+ loopKeepAliveCount_--;
+ } else {
+ add([=] { loopKeepAliveCount_--; });
+ }
}
private: