00001 // BLAlarm.hh 00002 /* 00003 This source file is part of G4beamline, http://g4beamline.muonsinc.com 00004 Copyright (C) 2003,2004,2005,2006 by Tom Roberts, all rights reserved. 00005 00006 This program is free software; you can redistribute it and/or 00007 modify it under the terms of the GNU General Public License 00008 as published by the Free Software Foundation; either version 2 00009 of the License, or (at your option) any later version. 00010 00011 This program is distributed in the hope that it will be useful, 00012 but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 GNU General Public License for more details. 00015 00016 http://www.gnu.org/copyleft/gpl.html 00017 */ 00018 00019 #ifndef BLALARM_HH 00020 #define BLALARM_HH 00021 00022 /** class BLAlarm implements an alarm clock. 00023 * used to prevent an infinite tracking loop from hanging an entire job. 00024 * 00025 * If BLSignal is also used, BLSignal::init() must be called first. 00026 **/ 00027 class BLAlarm { 00028 public: 00029 /// clear will clear any alarm. 00030 static void clear(); 00031 00032 /// set() sets an alarm in the future. 00033 /// Implicitly clears any previous alarm. 00034 /// seconds <= 0 does a clear(). 00035 static void set(int seconds); 00036 00037 /// init() will setup the signal handler 00038 /// Must be called before set(). 00039 static void init(); 00040 00041 private: 00042 /// sighandler() handles the alarm signal 00043 static void sighandler(int sig); 00044 }; 00045 00046 #endif // BLALARM_HH