From 63ab7767a37a99b5651f32e067aeb5fcbb7bd033 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Fri, 9 Sep 2016 17:21:17 +0200 Subject: [PATCH] event/Call: rethrow exceptions in calling thread --- src/event/Call.cxx | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/event/Call.cxx b/src/event/Call.cxx index 5d5bcadfa..82e192dd6 100644 --- a/src/event/Call.cxx +++ b/src/event/Call.cxx @@ -25,6 +25,8 @@ #include "thread/Cond.hxx" #include "Compiler.h" +#include + #include class BlockingCallMonitor final @@ -37,6 +39,8 @@ class BlockingCallMonitor final bool done; + std::exception_ptr exception; + public: BlockingCallMonitor(EventLoop &_loop, std::function &&_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;