From 3e68d7b45c2fc6830deddb07ccbbc0bdca7aec03 Mon Sep 17 00:00:00 2001 From: Dave Watson Date: Thu, 16 Apr 2015 11:15:19 -0700 Subject: [PATCH] runImmediatly fix Summary: Should also work if eventbase isn't looping Test Plan: added new unittest Reviewed By: hans@fb.com Subscribers: doug, folly-diffs@, yfeldblum, chalfant FB internal diff: D1984259 Signature: t1:1984259:1428691788:edb89424a48b8071a776d828300b7c1094f1c48f --- folly/io/async/EventBase.cpp | 2 +- folly/io/async/test/EventBaseTest.cpp | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/folly/io/async/EventBase.cpp b/folly/io/async/EventBase.cpp index 5ff171eb..b6cd8ca1 100644 --- a/folly/io/async/EventBase.cpp +++ b/folly/io/async/EventBase.cpp @@ -611,7 +611,7 @@ bool EventBase::runInEventBaseThreadAndWait(const Cob& fn) { } bool EventBase::runImmediatelyOrRunInEventBaseThreadAndWait(const Cob& fn) { - if (inRunningEventBaseThread()) { + if (isInEventBaseThread()) { fn(); return true; } else { diff --git a/folly/io/async/test/EventBaseTest.cpp b/folly/io/async/test/EventBaseTest.cpp index b9716a7c..349391a0 100644 --- a/folly/io/async/test/EventBaseTest.cpp +++ b/folly/io/async/test/EventBaseTest.cpp @@ -1246,6 +1246,15 @@ TEST(EventBaseTest, RunImmediatelyOrRunInEventBaseThreadAndWaitWithin) { }); } +TEST(EventBaseTest, RunImmediatelyOrRunInEventBaseThreadNotLooping) { + EventBase eb; + auto mutated = false; + eb.runImmediatelyOrRunInEventBaseThreadAndWait([&] { + mutated = true; + }); + EXPECT_TRUE(mutated); +} + /////////////////////////////////////////////////////////////////////////// // Tests for runInLoop() /////////////////////////////////////////////////////////////////////////// -- 2.34.1