runImmediatly fix
authorDave Watson <davejwatson@fb.com>
Thu, 16 Apr 2015 18:15:19 +0000 (11:15 -0700)
committerAlecs King <int@fb.com>
Mon, 27 Apr 2015 23:42:36 +0000 (16:42 -0700)
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
folly/io/async/test/EventBaseTest.cpp

index 5ff171eb2c3f7c043ceb04ee03b7df8793cf4e42..b6cd8ca120a7a4e5fd872a71e9a7eab19d7577af 100644 (file)
@@ -611,7 +611,7 @@ bool EventBase::runInEventBaseThreadAndWait(const Cob& fn) {
 }
 
 bool EventBase::runImmediatelyOrRunInEventBaseThreadAndWait(const Cob& fn) {
-  if (inRunningEventBaseThread()) {
+  if (isInEventBaseThread()) {
     fn();
     return true;
   } else {
index b9716a7cc9d1bef9c18ed42aa961eec0ab7eafab..349391a01190893fba38c43c1216b258beca1b6e 100644 (file)
@@ -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()
 ///////////////////////////////////////////////////////////////////////////