Celeritas
0.5.0-56+6b053cd
|
Catch the given signal type within the scope of the handler. More...
#include <ScopedSignalHandler.hh>
Public Types | |
Type aliases | |
using | signal_type = int |
Public Member Functions | |
ScopedSignalHandler ()=default | |
Default to not handling any signals. | |
ScopedSignalHandler (signal_type) | |
Handle the given signal type. | |
ScopedSignalHandler (std::initializer_list< signal_type >) | |
Handle the given signal type. | |
~ScopedSignalHandler () | |
Release the given signal. More... | |
bool | operator() () const |
Return whether a signal was intercepted. | |
operator bool () const | |
True if handling a signal. | |
ScopedSignalHandler (ScopedSignalHandler const &)=delete | |
ScopedSignalHandler & | operator= (ScopedSignalHandler const &)=delete |
ScopedSignalHandler (ScopedSignalHandler &&) noexcept | |
Move construct. | |
ScopedSignalHandler & | operator= (ScopedSignalHandler &&) noexcept |
Move assign. | |
void | swap (ScopedSignalHandler &other) noexcept |
Swap. | |
Static Public Member Functions | |
static bool | allow_signals () |
Whether signal handling is enabled. | |
static int | raise (signal_type sig) |
Raise a signal visible only to ScopedSignalHandler (for testing). More... | |
Catch the given signal type within the scope of the handler.
On instantiation with a non-empty argument, this class registers a signal handler for the given signal. A class instance is true if and only if the class is handling a signal. The instance's "call" operator will check and return whether the assigned signal has been caught. The move-assign operator can be used to unregister the handle.
When the class exits scope, the signal for the active type will be cleared.
Signal handling can be disabled by setting the environment variable CELER_DISABLE_SIGNALS
to a non-empty value, but hopefully this will not be necessary because signal handling should be used sparingly.
celeritas::ScopedSignalHandler::~ScopedSignalHandler | ( | ) |
Release the given signal.
This destructor is not thread-safe; it could have a race condition if a signal is sent while our signal bit is being cleared.
|
static |
Raise a signal visible only to ScopedSignalHandler (for testing).
This function always returns zero, indicating "success", to conform to the C++ standard library function.