SHOGUN  3.2.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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 #ifndef DISABLE_CANCEL_CALLBACK
17 namespace shogun
18 {
19 extern void (*sg_cancel_computations)(bool &delayed, bool &immediately);
20 }
21 #endif
22 
23 #include <shogun/lib/config.h>
25 #include <shogun/base/SGObject.h>
26 
27 #ifndef WIN32
28 #include <signal.h>
29 #define NUMTRAPPEDSIGS 2
30 
31 namespace shogun
32 {
48 class CSignal : public CSGObject
49 {
50  public:
52  CSignal();
53  virtual ~CSignal();
54 
59  static void handler(int signal);
60 
65  static bool set_handler();
66 
71  static bool unset_handler();
72 
74  static void clear();
75 
77  static void clear_cancel();
78 
80  static void set_cancel(bool immediately=false);
81 
86  static inline bool cancel_computations()
87  {
88 #ifndef DISABLE_CANCEL_CALLBACK
91 #endif
93  throw ShogunException("Computations have been cancelled immediately");
94 
95  return cancel_computation;
96  }
97 
99  virtual const char* get_name() const { return "Signal"; }
100 
101  protected:
103  static int signals[NUMTRAPPEDSIGS];
104 
106  static struct sigaction oldsigaction[NUMTRAPPEDSIGS];
107 
109  static bool active;
110 
112  static bool cancel_computation;
113 
115  static bool cancel_immediately;
116 };
117 }
118 #endif // WIN32
119 #endif // __SIGNAL__H_

SHOGUN Machine Learning Toolbox - Documentation