From 83ae6503e87c7f5237fb0f1602793c126436495a Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Wed, 25 Jan 2017 13:37:02 +0100 Subject: Fix interrupt handling --- src/libutil/util.hh | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'src/libutil/util.hh') diff --git a/src/libutil/util.hh b/src/libutil/util.hh index b68d48582b34..07141ffed6b5 100644 --- a/src/libutil/util.hh +++ b/src/libutil/util.hh @@ -433,5 +433,21 @@ struct InterruptCallback std::unique_ptr createInterruptCallback( std::function callback); +void triggerInterrupt(); + +/* A RAII class that causes the current thread to receive SIGUSR1 when + the signal handler thread receives SIGINT. That is, this allows + SIGINT to be multiplexed to multiple threads. */ +struct ReceiveInterrupts +{ + pthread_t target; + std::unique_ptr callback; + + ReceiveInterrupts() + : target(pthread_self()) + , callback(createInterruptCallback([&]() { pthread_kill(target, SIGUSR1); })) + { } +}; + } -- cgit 1.4.1