Scarab  v3.1.0
Project 8 C++ Utility Library
Public Member Functions | Static Public Member Functions | Private Types | Static Private Attributes | List of all members
signal_handler Class Reference

Deals with cleanly exiting an application, and includes signal and std::terminate handler functions. More...

#include <signal_handler.hh>

Public Member Functions

 signal_handler ()
 
virtual ~signal_handler ()
 
void add_cancelable (cancelable *a_cancelable)
 Add a cancelable object. More...
 
void remove_cancelable (cancelable *a_cancelable)
 Remove a cancelable object. More...
 
void reset ()
 Remove all cancelables and signal handling. More...
 
 snake_case_mv_accessible_static_noset (bool, exited)
 
 snake_case_mv_accessible_static (int, return_code)
 
 snake_case_mv_accessible_static_noset (bool, handling_sig_abrt)
 
 snake_case_mv_accessible_static_noset (bool, handling_sig_term)
 
 snake_case_mv_accessible_static_noset (bool, handling_sig_int)
 
 snake_case_mv_accessible_static_noset (bool, handling_sig_quit)
 

Static Public Member Functions

static void add_cancelable_s (cancelable *a_cancelable)
 Static version: add a cancelable object. More...
 
static void remove_cancelable_s (cancelable *a_cancelable)
 Static version: remove a cancelable object. More...
 
static void handle_terminate () noexcept
 Handler for std::terminate – does not cleanup memory or threads. More...
 
static void handle_exit_error (int a_sig)
 Handler for error signals – cleanly exits. More...
 
static void handle_exit_success (int a_sig)
 Handler for success signals – cleanly exits. More...
 
static void terminate (int a_code) noexcept
 Main terminate function – does not cleanup memory or threads. More...
 
static void exit (int a_code)
 Main exit function – cleanly exits. More...
 
static void print_current_exception (bool a_use_logging)
 Prints the current exception, if there is one. More...
 
static void print_stack_trace (bool a_use_logging)
 Prints the stack trace. More...
 
static void cancel_all (int a_code)
 Asynchronous call to cancel all cancelables with the given exit code. More...
 

Private Types

typedef std::set< cancelable *> cancelers
 
typedef cancelers::const_iterator cancelers_cit_t
 
typedef cancelers::iterator cancelers_it_t
 

Static Private Attributes

static cancelers s_cancelers
 
static std::recursive_mutex s_mutex
 

Detailed Description

Deals with cleanly exiting an application, and includes signal and std::terminate handler functions.

Author
N. S. Oblath

This class differentiates between two different ways of finishing a program:

Termination occurs in situations where the program must finish immediately. These are the situations in which std::terminate is used, for example, or there are unhandled exceptions. This can occur during execution, or even during static initialization and cleanup. Therefore only minimal global resources are assumed to be available (e.g. std::cerr). See https://akrzemi1.wordpress.com/2011/10/05/using-stdterminate/ for more information about the way in which termination can be handled. Termination can be commenced by:

Exiting occurs in situations where cleanly shutting down is possible. This includes both successful exiting and exiting with an error condition. signal_handler will be responsible for cancelling all threads that it knows about (via add_cancelable()). After the exit process is complete, it's the responsiblity of the program to stop execution. The program can use get_exited() to check whether the exit process has been used. Exiting can be commenced by:

Definition at line 64 of file signal_handler.hh.

Member Typedef Documentation

◆ cancelers

typedef std::set< cancelable* > cancelers
private

Definition at line 109 of file signal_handler.hh.

◆ cancelers_cit_t

typedef cancelers::const_iterator cancelers_cit_t
private

Definition at line 110 of file signal_handler.hh.

◆ cancelers_it_t

typedef cancelers::iterator cancelers_it_t
private

Definition at line 111 of file signal_handler.hh.

Constructor & Destructor Documentation

◆ signal_handler()

Definition at line 56 of file signal_handler.cc.

◆ ~signal_handler()

~signal_handler ( )
virtual

Definition at line 112 of file signal_handler.cc.

Member Function Documentation

◆ add_cancelable()

void add_cancelable ( scarab::cancelable a_cancelable)

Add a cancelable object.

Definition at line 115 of file signal_handler.cc.

◆ add_cancelable_s()

void add_cancelable_s ( scarab::cancelable a_cancelable)
static

Static version: add a cancelable object.

Definition at line 127 of file signal_handler.cc.

◆ cancel_all()

void cancel_all ( int  a_code)
static

Asynchronous call to cancel all cancelables with the given exit code.

Definition at line 287 of file signal_handler.cc.

◆ exit()

void exit ( int  a_code)
static

Main exit function – cleanly exits.

Definition at line 222 of file signal_handler.cc.

◆ handle_exit_error()

void handle_exit_error ( int  a_sig)
static

Handler for error signals – cleanly exits.

Definition at line 194 of file signal_handler.cc.

◆ handle_exit_success()

void handle_exit_success ( int  a_sig)
static

Handler for success signals – cleanly exits.

Definition at line 202 of file signal_handler.cc.

◆ handle_terminate()

void handle_terminate ( )
staticnoexcept

Handler for std::terminate – does not cleanup memory or threads.

Definition at line 189 of file signal_handler.cc.

◆ print_current_exception()

void print_current_exception ( bool  a_use_logging)
static

Prints the current exception, if there is one.

Definition at line 236 of file signal_handler.cc.

◆ print_stack_trace()

void print_stack_trace ( bool  a_use_logging)
static

Prints the stack trace.

Definition at line 262 of file signal_handler.cc.

◆ remove_cancelable()

void remove_cancelable ( scarab::cancelable a_cancelable)

Remove a cancelable object.

Definition at line 121 of file signal_handler.cc.

◆ remove_cancelable_s()

void remove_cancelable_s ( scarab::cancelable a_cancelable)
static

Static version: remove a cancelable object.

Definition at line 134 of file signal_handler.cc.

◆ reset()

void reset ( )

Remove all cancelables and signal handling.

Definition at line 141 of file signal_handler.cc.

◆ snake_case_mv_accessible_static()

snake_case_mv_accessible_static ( int  ,
return_code   
)

◆ snake_case_mv_accessible_static_noset() [1/5]

snake_case_mv_accessible_static_noset ( bool  ,
exited   
)

◆ snake_case_mv_accessible_static_noset() [2/5]

snake_case_mv_accessible_static_noset ( bool  ,
handling_sig_abrt   
)

◆ snake_case_mv_accessible_static_noset() [3/5]

snake_case_mv_accessible_static_noset ( bool  ,
handling_sig_term   
)

◆ snake_case_mv_accessible_static_noset() [4/5]

snake_case_mv_accessible_static_noset ( bool  ,
handling_sig_int   
)

◆ snake_case_mv_accessible_static_noset() [5/5]

snake_case_mv_accessible_static_noset ( bool  ,
handling_sig_quit   
)

◆ terminate()

void terminate ( int  a_code)
staticnoexcept

Main terminate function – does not cleanup memory or threads.

Definition at line 210 of file signal_handler.cc.

Member Data Documentation

◆ s_cancelers

signal_handler::cancelers s_cancelers
staticprivate

Definition at line 113 of file signal_handler.hh.

◆ s_mutex

std::recursive_mutex s_mutex
staticprivate

Definition at line 114 of file signal_handler.hh.


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