From bd122aa433bc14991769da073b407edd4a6683b5 Mon Sep 17 00:00:00 2001 From: Mahmoud Al-Qudsi Date: Tue, 2 Oct 2018 13:20:48 -0500 Subject: [PATCH] Add RAII wrapper for signal_block/signal_unblock --- src/signal.h | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/signal.h b/src/signal.h index dcbc3be75..fa5af8682 100644 --- a/src/signal.h +++ b/src/signal.h @@ -40,4 +40,17 @@ bool signal_is_blocked(); /// Returns signals with non-default handlers. void get_signals_with_handlers(sigset_t *set); + +/// A RAII wrapper for signal_block/signal_unblock that triggers a signal block on creation, and then +/// automatically releases the block when the object is destroyed, handling control flow and exceptions. +struct signal_block_t { + signal_block_t() { + signal_block(); + } + + ~signal_block_t() { + signal_unblock(); + } +}; + #endif