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 "
* 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