11 #include <shogun/lib/config.h> 36 SG_PRINT(
"error uninitalizing signal handler\n")
43 SG_SPRINT(
"\nImmediately return to prompt / Prematurely finish computations / Do nothing (I/P/D)? ")
44 char answer=fgetc(stdin);
53 else if (answer ==
'P')
61 SG_SPRINT(
"unknown signal %d received\n", signal)
73 sigaddset(&st, signals[i]);
75 #if !(defined(__INTERIX) || defined(__MINGW64__) || defined(_MSC_VER) || defined(__MINGW32__)) 76 act.sa_sigaction=NULL;
84 if (sigaction(signals[i], &act, &oldsigaction[i]))
87 for (int32_t j=i-1; j>=0; j--)
88 sigaction(signals[i], &oldsigaction[i], NULL);
110 if (sigaction(signals[i], &oldsigaction[i], NULL))
112 SG_SPRINT(
"error uninitalizing signal handler for signal %d\n", signals[i])
128 cancel_computation=
false;
129 cancel_immediately=
false;
134 cancel_computation=
true;
137 cancel_immediately=
true;
147 #if defined(__MINGW64__) || defined(_MSC_VER) || defined(__MINGW32__) 148 #define SIGBAD(signo) ( (signo) <=0 || (signo) >=NSIG) 149 Sigfunc *handlers[NSIG]={0};
151 int sigaddset(sigset_t *
set,
int signo)
157 *
set |= 1 << (signo-1);
161 int sigaction(
int signo,
const struct sigaction *act,
struct sigaction *oact)
169 oact->sa_handler = handlers[signo];
174 handlers[signo]=act->sa_handler;
static bool set_handler()
void(* sg_print_error)(FILE *target, const char *str)
function called to print error messages
Class SGObject is the base class of all shogun objects.
static bool cancel_computation
static void clear_cancel()
static bool unset_handler()
static void handler(int signal)
static int signals[NUMTRAPPEDSIGS]
all of classes and functions are contained in the shogun namespace
Class Signal implements signal handling to e.g. allow ctrl+c to cancel a long running process...
static struct sigaction oldsigaction[NUMTRAPPEDSIGS]
static void set_cancel(bool immediately=false)
static bool cancel_immediately