From b2d64a0a3e797231391d9ce373f7c0109793d287 Mon Sep 17 00:00:00 2001 From: Yedidya Feldblum Date: Tue, 3 Oct 2017 23:50:27 -0700 Subject: [PATCH] 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 --- folly/io/async/VirtualEventBase.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) 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); } -- 2.34.1