Commit 31d4d5d6 authored by Yedidya Feldblum's avatar Yedidya Feldblum Committed by Sara Golemon

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
parent b6741322
......@@ -20,12 +20,13 @@
#include <folly/io/async/EventBase.h>
#include <folly/Baton.h>
#include <folly/ThreadName.h>
#include <folly/io/async/NotificationQueue.h>
#include <boost/static_assert.hpp>
#include <condition_variable>
#include <fcntl.h>
#include <mutex>
#include <pthread.h>
#include <unistd.h>
......@@ -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<std::mutex> l(m);
ready = true;
l.unlock();
cv.notify_one();
};
fn(arg);
ready.post();
});
ready.wait();
std::unique_lock<std::mutex> 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<std::mutex> l(m);
ready = true;
l.unlock();
cv.notify_one();
};
fn();
ready.post();
});
ready.wait();
std::unique_lock<std::mutex> l(m);
cv.wait(l, [&] { return ready; });
return true;
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment