NutsBarrier.hh

Go to the documentation of this file.
00001 #ifndef NUTSBARRIER_HH_
00002 # define NUTSBARRIER_HH_
00003 
00004 # include <sys/times.h>
00005 # include <signal.h>
00006 # include <cassert>
00007 # include "tools.hh"
00008 
00009 namespace xml { class XMLConfig; }
00010 
00017 # define LOOP_TO_TURN_RATIO 5
00018 
00019 // receive signals
00020 class SignalHandler
00021 {
00022 protected:
00023   SignalHandler();
00024   virtual ~SignalHandler();
00025 
00026   virtual void sigSegv() = 0;
00027   virtual void sigBus() = 0;
00028   virtual void sigAlrm() = 0;
00029 
00030 private:
00031   friend class NutsBarrier;
00032   static void catchSignal(int signal);
00033   static SignalHandler* inst_;
00034 };
00035 
00047 class NutsBarrier
00048 {
00049 public:
00050   NutsBarrier();
00051   ~NutsBarrier();
00052 
00053   
00054   int           getTimeRemaining() const;
00055   int           getExtraTimeRemaining() const;
00056   
00057   void          setConfigLimits(const xml::XMLConfig& cfg);
00058   void          setTimeLimitValue(int time, int reserve); // in millisecond
00059   void          setMemoryLimitValue(int memory); // in kbytes.
00060   void          setSignalHandler(SignalHandler* hdl);
00061   
00062   void          setTimeLimit();
00063   void          unsetTimeLimit();
00064   void          setSignalCatch();
00065   void          unsetSignalCatch();
00066 
00067 private:
00068   int           time_limit_;
00069   int           time_reserve_;
00070 
00071   struct sigaction prev_sigbus_;
00072   struct sigaction prev_sigsegv_;
00073 
00074   int           autoTimeSelect() const;
00075   int           timerSub(const struct itimerval *start, const struct itimerval *end) const;
00076   void          dumbLoop() const;
00077 
00078   static void   reachHardLimit(int);
00079   struct itimerval time_start_;
00080   
00081   mutable int   ref_speed_;
00082   SignalHandler* hdl_;
00083 };
00084 
00085 
00086 #endif /* !NUTSBARRIER_HH_ */
00087 

Generated on Sat Jun 23 16:07:23 2007 for Stechec/TBT by  doxygen 1.4.7