From: Dave Watson Date: Thu, 16 Apr 2015 18:15:19 +0000 (-0700) Subject: runImmediatly fix X-Git-Tag: v0.36.0~34 X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=3e68d7b45c2fc6830deddb07ccbbc0bdca7aec03;p=folly.git 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 --- 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() ///////////////////////////////////////////////////////////////////////////