From: Yedidya Feldblum Date: Wed, 4 Feb 2015 23:10:51 +0000 (-0800) Subject: Avoid EventBase depending on Baton (mutex/condvar variant). X-Git-Tag: v0.25.0~19 X-Git-Url: http://plrg.eecs.uci.edu/git/?a=commitdiff_plain;h=31d4d5d6bddb9eddb275b7415ad36866905a1660;p=folly.git Avoid EventBase depending on Baton (mutex/condvar variant). Summary: [Folly] Avoid EventBase depending on Baton (mutex/condvar variant). Test Plan: Unit tests: * folly/io/async/test/EventBaseTest.cpp Reviewed By: subodh@fb.com Subscribers: trunkagent, fma, folly-diffs@, yfeldblum, dougw, brettp FB internal diff: D1823407 Signature: t1:1823407:1423088450:71ae1673ed8067103e2aaa1ac9b239eae9ebe9de Blame Revision: D1810764 --- diff --git a/folly/io/async/EventBase.cpp b/folly/io/async/EventBase.cpp index 00aa9d80..8ec54b67 100644 --- a/folly/io/async/EventBase.cpp +++ b/folly/io/async/EventBase.cpp @@ -20,12 +20,13 @@ #include -#include #include #include #include +#include #include +#include #include #include @@ -570,12 +571,20 @@ bool EventBase::runInEventBaseThreadAndWait(void (*fn)(void*), void* arg) { return false; } - Baton<> ready; + bool ready = false; + std::mutex m; + std::condition_variable cv; runInEventBaseThread([&] { + SCOPE_EXIT { + std::unique_lock l(m); + ready = true; + l.unlock(); + cv.notify_one(); + }; fn(arg); - ready.post(); }); - ready.wait(); + std::unique_lock l(m); + cv.wait(l, [&] { return ready; }); return true; } @@ -587,12 +596,20 @@ bool EventBase::runInEventBaseThreadAndWait(const Cob& fn) { return false; } - Baton<> ready; + bool ready = false; + std::mutex m; + std::condition_variable cv; runInEventBaseThread([&] { + SCOPE_EXIT { + std::unique_lock l(m); + ready = true; + l.unlock(); + cv.notify_one(); + }; fn(); - ready.post(); }); - ready.wait(); + std::unique_lock l(m); + cv.wait(l, [&] { return ready; }); return true; }