From 31d4d5d6bddb9eddb275b7415ad36866905a1660 Mon Sep 17 00:00:00 2001 From: Yedidya Feldblum Date: Wed, 4 Feb 2015 15:10:51 -0800 Subject: [PATCH] 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 --- folly/io/async/EventBase.cpp | 31 ++++++++++++++++++++++++------- 1 file changed, 24 insertions(+), 7 deletions(-) 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; } -- 2.34.1