event/Call: rethrow exceptions in calling thread

This commit is contained in:
Max Kellermann 2016-09-09 17:21:17 +02:00
parent 20894d1c5e
commit 63ab7767a3

View File

@ -25,6 +25,8 @@
#include "thread/Cond.hxx"
#include "Compiler.h"
#include <exception>
#include <assert.h>
class BlockingCallMonitor final
@ -37,6 +39,8 @@ class BlockingCallMonitor final
bool done;
std::exception_ptr exception;
public:
BlockingCallMonitor(EventLoop &_loop, std::function<void()> &&_f)
:DeferredMonitor(_loop), f(std::move(_f)), done(false) {}
@ -50,13 +54,20 @@ public:
while (!done)
cond.wait(mutex);
mutex.unlock();
if (exception)
std::rethrow_exception(exception);
}
private:
virtual void RunDeferred() override {
assert(!done);
f();
try {
f();
} catch (...) {
exception = std::current_exception();
}
mutex.lock();
done = true;