Commit 777002cb authored by Yedidya Feldblum's avatar Yedidya Feldblum Committed by Sara Golemon

Dedupe the implementations of EventBase::runInEventBaseThreadAndWait.

Summary: [Folly] Dedupe the implementations of EventBase::runInEventBaseThreadAndWait.

Test Plan:
Unit tests:
* `folly/io/async/test/EventBaseTest.cpp`

Reviewed By: subodh@fb.com

Subscribers: trunkagent, folly-diffs@, yfeldblum, dougw, brettp

FB internal diff: D1826291

Signature: t1:1826291:1423225534:42264d8dcc8adec6b90ac8a3d6ce1f4b98f29297

Blame Revision: D1810764, D1823407
parent 75d52926
......@@ -564,31 +564,6 @@ bool EventBase::runInEventBaseThread(const Cob& fn) {
return true;
}
bool EventBase::runInEventBaseThreadAndWait(void (*fn)(void*), void* arg) {
if (inRunningEventBaseThread()) {
LOG(ERROR) << "EventBase " << this << ": Waiting in the event loop is not "
<< "allowed";
return false;
}
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);
});
std::unique_lock<std::mutex> l(m);
cv.wait(l, [&] { return ready; });
return true;
}
bool EventBase::runInEventBaseThreadAndWait(const Cob& fn) {
if (inRunningEventBaseThread()) {
LOG(ERROR) << "EventBase " << this << ": Waiting in the event loop is not "
......
......@@ -360,7 +360,9 @@ class EventBase : private boost::noncopyable,
* Like runInEventBaseThread, but the caller waits for the callback to be
* executed.
*/
bool runInEventBaseThreadAndWait(void (*fn)(void*), void* arg);
bool runInEventBaseThreadAndWait(void (*fn)(void*), void* arg) {
return runInEventBaseThreadAndWait(std::bind(fn, arg));
}
/*
* Like runInEventBaseThread, but the caller waits for the callback to be
......
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