SHOGUN  v2.0.0
 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 #ifndef DISABLE_CANCEL_CALLBACK
15 namespace shogun
16 {
17 extern void (*sg_cancel_computations)(bool &delayed, bool &immediately);
18 }
19 #endif
20 
21 #include <shogun/lib/config.h>
23 #include <shogun/base/SGObject.h>
24 #include <shogun/base/init.h>
25 
26 #ifndef WIN32
27 #include <signal.h>
28 #define NUMTRAPPEDSIGS 2
29 
30 namespace shogun
31 {
47 class CSignal : public CSGObject
48 {
49  public:
51  CSignal();
52  virtual ~CSignal();
53 
58  static void handler(int signal);
59 
64  static bool set_handler();
65 
70  static bool unset_handler();
71 
73  static void clear();
74 
76  static void clear_cancel();
77 
79  static void set_cancel(bool immediately=false);
80 
85  static inline bool cancel_computations()
86  {
87 #ifndef DISABLE_CANCEL_CALLBACK
90 #endif
92  throw ShogunException("Computations have been cancelled immediately");
93 
94  return cancel_computation;
95  }
96 
98  inline virtual const char* get_name() const { return "Signal"; }
99 
100  protected:
102  static int signals[NUMTRAPPEDSIGS];
103 
105  static struct sigaction oldsigaction[NUMTRAPPEDSIGS];
106 
108  static bool active;
109 
111  static bool cancel_computation;
112 
114  static bool cancel_immediately;
115 };
116 #endif // WIN32
117 }
118 #endif // __SIGNAL__H_

SHOGUN Machine Learning Toolbox - Documentation