about summary refs log tree commit diff
path: root/src/libutil/util.hh
diff options
context:
space:
mode:
authorEelco Dolstra <edolstra@gmail.com>2017-01-25T12·37+0100
committerEelco Dolstra <edolstra@gmail.com>2017-01-26T19·40+0100
commit83ae6503e87c7f5237fb0f1602793c126436495a (patch)
treee439570378a11b6ec6d1ef381aed4b5e1613c5bb /src/libutil/util.hh
parent951357e5fb4cd0804e729866f204b635add926a3 (diff)
Fix interrupt handling
Diffstat (limited to 'src/libutil/util.hh')
-rw-r--r--src/libutil/util.hh16
1 files changed, 16 insertions, 0 deletions
diff --git a/src/libutil/util.hh b/src/libutil/util.hh
index b68d48582b..07141ffed6 100644
--- a/src/libutil/util.hh
+++ b/src/libutil/util.hh
@@ -433,5 +433,21 @@ struct InterruptCallback
 std::unique_ptr<InterruptCallback> createInterruptCallback(
     std::function<void()> 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<InterruptCallback> callback;
+
+    ReceiveInterrupts()
+        : target(pthread_self())
+        , callback(createInterruptCallback([&]() { pthread_kill(target, SIGUSR1); }))
+    { }
+};
+
 
 }