Aleph-w 3.0
A C++ Library for Data Structures and Algorithms
Loading...
Searching...
No Matches
SignalBlocker Class Reference

RAII wrapper for temporarily blocking signals. More...

#include <ah-signal.H>

Public Member Functions

 SignalBlocker (const SignalSet &signals)
 Blocks the signals in the given set.
 
 SignalBlocker (std::initializer_list< int > signals)
 Blocks the signals specified in the initializer list.
 
 SignalBlocker (int signo)
 Blocks a single signal.
 
 ~SignalBlocker ()
 Restores the previous signal mask.
 
void release () noexcept
 Releases ownership - the mask won't be restored on destruction.
 
const sigset_t & previous_mask () const noexcept
 Returns the previous signal mask that will be restored.
 
 SignalBlocker (const SignalBlocker &)=delete
 
SignalBlockeroperator= (const SignalBlocker &)=delete
 
 SignalBlocker (SignalBlocker &&other) noexcept
 
SignalBlockeroperator= (SignalBlocker &&other) noexcept
 

Private Attributes

sigset_t old_mask_
 
bool active_ = true
 

Detailed Description

RAII wrapper for temporarily blocking signals.

Blocks the specified signals on construction and restores the previous signal mask on destruction.

Example

{
// Block SIGINT and SIGTERM in this scope
SignalBlocker blocker({SIGINT, SIGTERM});
// Critical section - these signals won't interrupt
do_critical_work();
} // Previous mask is restored here
RAII wrapper for temporarily blocking signals.
Definition ah-signal.H:233
Note
Uses sigprocmask() which affects the calling thread in single-threaded programs or the process signal mask.

Definition at line 232 of file ah-signal.H.

Constructor & Destructor Documentation

◆ SignalBlocker() [1/5]

SignalBlocker::SignalBlocker ( const SignalSet signals)
inlineexplicit

Blocks the signals in the given set.

Parameters
signalsThe set of signals to block.
Exceptions
SignalErrorif sigprocmask fails.

Definition at line 243 of file ah-signal.H.

References SignalSet::get(), and old_mask_.

◆ SignalBlocker() [2/5]

SignalBlocker::SignalBlocker ( std::initializer_list< int >  signals)
inline

Blocks the signals specified in the initializer list.

Parameters
signalsList of signal numbers to block.
Exceptions
SignalErrorif sigprocmask fails.

Definition at line 254 of file ah-signal.H.

◆ SignalBlocker() [3/5]

SignalBlocker::SignalBlocker ( int  signo)
inlineexplicit

Blocks a single signal.

Parameters
signoThe signal number to block.
Exceptions
SignalErrorif sigprocmask fails.

Definition at line 262 of file ah-signal.H.

◆ ~SignalBlocker()

SignalBlocker::~SignalBlocker ( )
inline

Restores the previous signal mask.

Definition at line 266 of file ah-signal.H.

References active_, and old_mask_.

◆ SignalBlocker() [4/5]

SignalBlocker::SignalBlocker ( const SignalBlocker )
delete

◆ SignalBlocker() [5/5]

SignalBlocker::SignalBlocker ( SignalBlocker &&  other)
inlinenoexcept

Definition at line 286 of file ah-signal.H.

Member Function Documentation

◆ operator=() [1/2]

SignalBlocker & SignalBlocker::operator= ( const SignalBlocker )
delete

◆ operator=() [2/2]

SignalBlocker & SignalBlocker::operator= ( SignalBlocker &&  other)
inlinenoexcept

Definition at line 292 of file ah-signal.H.

References active_, and old_mask_.

◆ previous_mask()

const sigset_t & SignalBlocker::previous_mask ( ) const
inlinenoexcept

Returns the previous signal mask that will be restored.

Definition at line 276 of file ah-signal.H.

References old_mask_.

◆ release()

void SignalBlocker::release ( )
inlinenoexcept

Releases ownership - the mask won't be restored on destruction.

Definition at line 273 of file ah-signal.H.

References active_.

Referenced by TEST_F().

Member Data Documentation

◆ active_

bool SignalBlocker::active_ = true
private

Definition at line 235 of file ah-signal.H.

Referenced by ~SignalBlocker(), operator=(), and release().

◆ old_mask_

sigset_t SignalBlocker::old_mask_
private

Definition at line 234 of file ah-signal.H.

Referenced by SignalBlocker(), ~SignalBlocker(), operator=(), and previous_mask().


The documentation for this class was generated from the following file: