SHOGUN  6.0.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules
Signal.h
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or modify
3  * it under the terms of the GNU General Public License as published by
4  * the Free Software Foundation; either version 3 of the License, or
5  * (at your option) any later version.
6  *
7  * Written (W) 1999-2009 Soeren Sonnenburg
8  * Copyright (C) 1999-2009 Fraunhofer Institute FIRST and Max-Planck-Society
9  */
10 
11 #ifndef __SIGNAL__H_
12 #define __SIGNAL__H_
13 
14 #include <shogun/lib/config.h>
15 
16 #if defined(__MINGW64__) || defined(_MSC_VER)
17 typedef unsigned long sigset_t;
18 #endif
19 #if defined(__MINGW32__) && !defined(__MINGW64__)
20 typedef int sigset_t;
21 #endif
22 
23 #ifndef SIGURG
24 #define SIGURG -16
25 #endif
26 
27 #if defined(__MINGW64__) || defined(_MSC_VER) || defined(__MINGW32__)
28 typedef void Sigfunc (int);
29 
30 struct sigaction {
31  Sigfunc *sa_handler;
32  sigset_t sa_mask;
33  int sa_flags;
34 };
35 
36 #define sigemptyset(ptr) (*(ptr) = 0)
37 #define sigfillset(ptr) ( *(ptr) = ~(sigset_t)0,0)
38 
39 int sigaddset(sigset_t*, int);
40 int sigaction(int signo, const struct sigaction *act, struct sigaction *oact);
41 #endif
42 
43 #ifndef DISABLE_CANCEL_CALLBACK
44 namespace shogun
45 {
46 extern void (*sg_cancel_computations)(bool &delayed, bool &immediately);
47 }
48 #endif
49 
51 #include <shogun/base/SGObject.h>
52 
53 #include <csignal>
54 #define NUMTRAPPEDSIGS 2
55 
56 namespace shogun
57 {
73 class CSignal : public CSGObject
74 {
75  public:
77  CSignal();
78  virtual ~CSignal();
79 
84  static void handler(int signal);
85 
90  static bool set_handler();
91 
96  static bool unset_handler();
97 
99  static void clear();
100 
102  static void clear_cancel();
103 
105  static void set_cancel(bool immediately=false);
106 
111  static inline bool cancel_computations()
112  {
113 #ifndef DISABLE_CANCEL_CALLBACK
116 #endif
117  if (cancel_immediately)
118  throw ShogunException("Computations have been cancelled immediately");
119 
120  return cancel_computation;
121  }
122 
124  virtual const char* get_name() const { return "Signal"; }
125 
126  protected:
128  static int signals[NUMTRAPPEDSIGS];
129 
131  static struct sigaction oldsigaction[NUMTRAPPEDSIGS];
132 
134  static bool active;
135 
137  static bool cancel_computation;
138 
140  static bool cancel_immediately;
141 };
142 }
143 #endif // __SIGNAL__H_
static bool set_handler()
Definition: Signal.cpp:64
Class ShogunException defines an exception which is thrown whenever an error inside of shogun occurs...
virtual const char * get_name() const
Definition: Signal.h:124
static bool active
Definition: Signal.h:134
Class SGObject is the base class of all shogun objects.
Definition: SGObject.h:125
static bool cancel_computation
Definition: Signal.h:137
static void clear_cancel()
Definition: Signal.cpp:126
static bool unset_handler()
Definition: Signal.cpp:102
#define NUMTRAPPEDSIGS
Definition: Signal.h:54
void(* sg_cancel_computations)(bool &delayed, bool &immediately)
function called to cancel things
Definition: init.cpp:54
static bool cancel_computations()
Definition: Signal.h:111
static void handler(int signal)
Definition: Signal.cpp:39
static int signals[NUMTRAPPEDSIGS]
Definition: Signal.h:128
static void clear()
Definition: Signal.cpp:140
virtual ~CSignal()
Definition: Signal.cpp:33
all of classes and functions are contained in the shogun namespace
Definition: class_list.h:18
Class Signal implements signal handling to e.g. allow ctrl+c to cancel a long running process...
Definition: Signal.h:73
static struct sigaction oldsigaction[NUMTRAPPEDSIGS]
Definition: Signal.h:131
static void set_cancel(bool immediately=false)
Definition: Signal.cpp:132
static bool cancel_immediately
Definition: Signal.h:140

SHOGUN Machine Learning Toolbox - Documentation