#include <BLAlarm.hh>
used to prevent an infinite tracking loop from hanging an entire job.
If BLSignal is also used, BLSignal::init() must be called first.
This class is 100% static.
Public Member Functions | |
int | timeRemaining () |
timeRemaining() returns the time remaining, in seconds. returns -1 if no alarm is set. | |
Static Public Member Functions | |
static void | clear () |
clear will clear any alarm. | |
static void | set (int seconds) |
set() sets an alarm in the future. Implicitly clears any previous alarm. seconds <= 0 does a clear(). | |
static void | init () |
init() will setup the signal handler. Must be called before set(). | |
static void(* | setCustomHandler (void(*handler)()))() |
setCustomhandler() sets a custom alarm handler. returns the previous handler, or 0 if none. | |
Static Private Member Functions | |
static void | sighandler (int sig) |
sighandler() handles the alarm signal | |
Static Private Attributes | |
static void(* | customHandler )() |
void BLAlarm::clear | ( | ) | [static] |
clear will clear any alarm.
Linux and Mac OS X handle alarm signals natively.
Referenced by BLManager::EndOfEventAction(), and BLManager::Notify().
void BLAlarm::set | ( | int | seconds | ) | [static] |
set() sets an alarm in the future. Implicitly clears any previous alarm. seconds <= 0 does a clear().
References alarm_time, NEVER, and BLTime::time().
Referenced by BLManager::BeginOfEventAction().
00129 { 00130 alarm(seconds < 0 ? 0 : seconds); 00131 if(seconds <= 0) 00132 alarm_time = NEVER; 00133 else 00134 alarm_time = BLTime::time() + seconds; 00135 }
void BLAlarm::init | ( | ) | [static] |
init() will setup the signal handler. Must be called before set().
References sighandler().
Referenced by BLManager::BLManager().
00138 { 00139 signal(SIGALRM,sighandler); 00140 }
static void(* BLAlarm::setCustomHandler | ( | void(*)() | handler | ) | [static] |
setCustomhandler() sets a custom alarm handler. returns the previous handler, or 0 if none.
int BLAlarm::timeRemaining | ( | ) |
timeRemaining() returns the time remaining, in seconds. returns -1 if no alarm is set.
References alarm_time, NEVER, and BLTime::time().
00166 { 00167 unsigned long t = BLTime::time(); 00168 if(t > alarm_time || alarm_time == NEVER) 00169 return -1; 00170 return alarm_time - t; 00171 00172 }
void BLAlarm::sighandler | ( | int | sig | ) | [static, private] |
sighandler() handles the alarm signal
References BLRunManager::abandonCurrentEvent(), alarm_time, customHandler, BLRunManager::getObject(), and NEVER.
Referenced by init().
00143 { 00144 alarm(0); 00145 alarm_time = NEVER; 00146 signal(sig,sighandler); 00147 00148 if(customHandler != 0) { 00149 (*customHandler)(); 00150 return; 00151 } 00152 00153 BLRunManager::getObject()->abandonCurrentEvent(); 00154 G4Exception("BLAlarm","Alarm Signal",FatalException, 00155 "SIGALRM fired, cannot be recovered"); 00156 }
void(* BLAlarm::customHandler)()=0 | ( | ) | [static, private] |
Referenced by sighandler().