/usr/include/shogun/lib/Signal.h is in libshogun-dev 3.2.0-7.3build4.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 | /*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* Written (W) 1999-2009 Soeren Sonnenburg
* Copyright (C) 1999-2009 Fraunhofer Institute FIRST and Max-Planck-Society
*/
#ifndef __SIGNAL__H_
#define __SIGNAL__H_
#ifndef DISABLE_CANCEL_CALLBACK
namespace shogun
{
extern void (*sg_cancel_computations)(bool &delayed, bool &immediately);
}
#endif
#include <shogun/lib/config.h>
#include <shogun/lib/ShogunException.h>
#include <shogun/base/SGObject.h>
#include <shogun/base/init.h>
#ifndef WIN32
#include <signal.h>
#define NUMTRAPPEDSIGS 2
namespace shogun
{
/** @brief Class Signal implements signal handling to e.g. allow ctrl+c to cancel a
* long running process.
*
* This is done in two ways:
*
* -# A signal handler is attached to trap the SIGINT and SIGURG signal.
* Pressing ctrl+c or sending the SIGINT (kill ...) signal to the shogun
* process will make shogun print a message asking to immediately exit the
* running method and to fall back to the command line.
* -# When an URG signal is received or ctrl+c P is pressed shogun will
* prematurely stop a method and continue execution. For example when an SVM
* solver takes a long time without progressing much, one might still be
* interested in the result and should thus send SIGURG or interactively
* prematurely stop the method
*/
class CSignal : public CSGObject
{
public:
/** default constructor */
CSignal();
virtual ~CSignal();
/** handler
*
* @param signal signal number
*/
static void handler(int signal);
/** set handler
*
* @return if setting was successful
*/
static bool set_handler();
/** unset handler
*
* @return if unsetting was successful
*/
static bool unset_handler();
/** clear signals */
static void clear();
/** clear cancel flag signals */
static void clear_cancel();
/** set cancel flag signals */
static void set_cancel(bool immediately=false);
/** cancel computations
*
* @return if computations should be cancelled
*/
static inline bool cancel_computations()
{
#ifndef DISABLE_CANCEL_CALLBACK
if (sg_cancel_computations)
sg_cancel_computations(cancel_computation, cancel_immediately);
#endif
if (cancel_immediately)
throw ShogunException("Computations have been cancelled immediately");
return cancel_computation;
}
/** @return object name */
virtual const char* get_name() const { return "Signal"; }
protected:
/** signals; handling external lib */
static int signals[NUMTRAPPEDSIGS];
/** signal actions */
static struct sigaction oldsigaction[NUMTRAPPEDSIGS];
/** active signal */
static bool active;
/** if computation should be cancelled */
static bool cancel_computation;
/** if shogun should return ASAP */
static bool cancel_immediately;
};
}
#endif // WIN32
#endif // __SIGNAL__H_
|