Go to the documentation of this file.
9 #ifndef EAGINE_SIGNAL_SWITCH_HPP
10 #define EAGINE_SIGNAL_SWITCH_HPP
28 : _intr_handler{std::signal(SIGINT, &_flip)}
29 , _term_handler{std::signal(SIGTERM, &_flip)} {}
33 std::signal(SIGINT, _intr_handler);
34 std::signal(SIGTERM, _term_handler);
55 return _state() == SIGINT;
60 return _state() == SIGTERM;
64 explicit operator bool() const noexcept {
65 return bool(_state());
69 static auto _state() noexcept -> volatile std::sig_atomic_t& {
70 static volatile std::sig_atomic_t state{0};
74 static void _flip(
int sig_num) {
78 using _sighandler_t = void(
int);
79 _sighandler_t* _intr_handler{
nullptr};
80 _sighandler_t* _term_handler{
nullptr};
85 #endif // EAGINE_SIGNAL_SWITCH_HPP
auto terminated() const noexcept -> bool
Indicates if the terminate signal was received.
Definition: signal_switch.hpp:59
Common code is placed in this namespace.
Definition: eagine.hpp:21
Installs handlers for interrupt signals and flips switch on receipt.
Definition: signal_switch.hpp:23
auto interrupted() const noexcept -> bool
Indicates if the interrupt signal was received.
Definition: signal_switch.hpp:54
signal_switch() noexcept
Default constructor. Stores the original handlers if any.
Definition: signal_switch.hpp:27
auto reset() noexcept -> signal_switch &
Resets the signal state as if no signal was received.
Definition: signal_switch.hpp:48
~signal_switch() noexcept
Destructor. Restores the original signal handlers.
Definition: signal_switch.hpp:32
auto operator=(signal_switch &&)=delete
Not move-assignable.