SHOGUN  4.1.0
 全部  命名空间 文件 函数 变量 类型定义 枚举 枚举值 友元 宏定义  
Signal.h
浏览该文件的文档.
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_
static bool set_handler()
Definition: Signal.cpp:67
Class ShogunException defines an exception which is thrown whenever an error inside of shogun occurs...
virtual const char * get_name() const
Definition: Signal.h:99
static bool active
Definition: Signal.h:109
Class SGObject is the base class of all shogun objects.
Definition: SGObject.h:112
static bool cancel_computation
Definition: Signal.h:112
static void clear_cancel()
Definition: Signal.cpp:129
static bool unset_handler()
Definition: Signal.cpp:105
#define NUMTRAPPEDSIGS
Definition: Signal.h:29
void(* sg_cancel_computations)(bool &delayed, bool &immediately)
function called to cancel things
Definition: init.cpp:51
static bool cancel_computations()
Definition: Signal.h:86
static void handler(int signal)
Definition: Signal.cpp:42
static int signals[NUMTRAPPEDSIGS]
Definition: Signal.h:103
static void clear()
Definition: Signal.cpp:143
virtual ~CSignal()
Definition: Signal.cpp:36
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:48
static struct sigaction oldsigaction[NUMTRAPPEDSIGS]
Definition: Signal.h:106
static void set_cancel(bool immediately=false)
Definition: Signal.cpp:135
static bool cancel_immediately
Definition: Signal.h:115

SHOGUN 机器学习工具包 - 项目文档