From: Yedidya Feldblum Date: Wed, 4 Oct 2017 06:50:27 +0000 (-0700) Subject: Let keep-alive tokens from VirtualEventBase be destroyed from any thread X-Git-Tag: v2017.10.09.00~14 X-Git-Url: http://plrg.eecs.uci.edu/git/?p=folly.git;a=commitdiff_plain;h=b2d64a0a3e797231391d9ce373f7c0109793d287 Let keep-alive tokens from VirtualEventBase be destroyed from any thread Summary: [Folly] Let keep-alive tokens from `VirtualEventBase` be destroyed from any thread. This case was missed in {D5951397} (facebook/folly@6f3b7616f3402355441c62ca60a36159435aa818). Reviewed By: andriigrynenko Differential Revision: D5970670 fbshipit-source-id: 19e2b00134516e68113234acd6111e21c3e23e8d --- diff --git a/folly/io/async/VirtualEventBase.h b/folly/io/async/VirtualEventBase.h index 4e62fb12..068e649f 100644 --- a/folly/io/async/VirtualEventBase.h +++ b/folly/io/async/VirtualEventBase.h @@ -118,7 +118,6 @@ class VirtualEventBase : public folly::Executor, public folly::TimeoutManager { /** * Returns you a handle which prevents VirtualEventBase from being destroyed. - * KeepAlive handle can be released from EventBase loop only. */ KeepAlive getKeepAliveToken() override { DCHECK(loopKeepAliveCount_ + loopKeepAliveCountAtomic_.load() > 0); @@ -137,7 +136,9 @@ class VirtualEventBase : public folly::Executor, public folly::TimeoutManager { protected: void keepAliveRelease() override { - getEventBase().dcheckIsInEventBaseThread(); + if (!getEventBase().inRunningEventBaseThread()) { + return getEventBase().add([=] { keepAliveRelease(); }); + } if (loopKeepAliveCountAtomic_.load()) { loopKeepAliveCount_ += loopKeepAliveCountAtomic_.exchange(0); }