00001
00002
00003 #ifndef Timer_HPP
00004 #define Timer_HPP
00005
00006 #include <j2k/Fred/Standard.hpp>
00007 #include <j2k/nto/Basic_PThread.hpp>
00008
00009 #include <unistd.h>
00010 #include <errno.h>
00011 #include <pthread.h>
00012 #include <signal.h>
00013 #include <sys/time.h>
00014
00015 #if !defined( linux )
00016
00017
00018 #include <sys/siginfo.h>
00019
00020 #endif
00021
00022
00023 #if defined( __QNXNTO__ )
00024
00025 #include <sys/neutrino.h>
00026
00027
00028 #include <sys/netmgr.h>
00029
00030 #endif
00031
00032
00033 #define TimerSignal SIGUSR1
00034
00035 class Timer;
00036
00037
00038
00039
00040 class Timer : public Basic_PThread {
00041
00042 public:
00043
00044 const ULONG Period_1_ms = 1000000L;
00045 const ULONG Period_10_ms = 10000000L;
00046 const ULONG Period_20_ms = 20000000L;
00047 const ULONG Period_50_ms = 50000000L;
00048 const ULONG Period_100_ms = 100000000L;
00049 const ULONG Period_250_ms = 250000000L;
00050 const ULONG Period_500_ms = 500000000L;
00051 const ULONG Period_750_ms = 750000000L;
00052
00053
00054 protected:
00055 static Timer* theTimer;
00056
00057
00058
00059 Timer( ULONG nsec = 0, ULONG sec = 0 );
00060
00061 virtual void run();
00062
00063 inline double getSpent();
00064 inline double getElapsed( _uint64 started );
00065 inline _uint64 getCycles();
00066
00067
00068 static void wrapper( int signo )
00069 {
00070 assert( signo == TimerSignal );
00071 theTimer->tick( signo );
00072 }
00073
00074
00075 virtual void tick( int signo ) = 0;
00076
00077
00078 private:
00079 clockid_t timerid;
00080 struct sigevent event;
00081 struct itimerspec t;
00082
00083 #if defined( __QNXNTO__ )
00084
00085 int pulse_id;
00086 int timer_pid;
00087 int chid;
00088
00089 timer_t timer_id;
00090 struct _pulse pulse;
00091
00092 #endif
00093
00094
00095 };
00096
00097 #endif