Main Page   Packages   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Search  

Timer Class Reference

#include <Timer.hpp>

Inheritance diagram for Timer::

Basic_PThread Basic_PThread List of all members.

Public Methods

 Timer (ULONG nsec, ULONG sec=0)
__inline void start ()
virtual void timedRun (int signo)=0

Static Public Methods

void wrapper (int signo)

Public Attributes

const ULONG Period_1_ms = 1000000L
const ULONG Period_10_ms = 10000000L
const ULONG Period_20_ms = 20000000L
const ULONG Period_50_ms = 50000000L
const ULONG Period_100_ms = 100000000L
const ULONG Period_250_ms = 250000000L
const ULONG Period_500_ms = 500000000L
const ULONG Period_750_ms = 750000000L

Protected Methods

 Timer (ULONG nsec=0, ULONG sec=0)
virtual void run ()
__inline double getSpent ()
__inline double getElapsed (_uint64 started)
__inline _uint64 getCycles ()
virtual void tick (int signo)=0
 Timer (ULONG nsec=0, ULONG sec=0)
virtual void run ()
__inline double getSpent ()
__inline double getElapsed (_uint64 started)
__inline _uint64 getCycles ()
virtual void tick (int signo)=0

Static Protected Methods

void wrapper (int signo)
void wrapper (int signo)

Static Protected Attributes

Timer * theTimer = NULL
Timer * theTimer

Private Attributes

clockid_t timerid
sigevent event
itimerspec t
sigevent event
itimerspec t
sigevent event
itimerspec t

Constructor & Destructor Documentation

Timer::Timer ULONG    nsec = 0,
ULONG    sec = 0
[protected]
 

Definition at line 18 of file Timer.cpp.

00019 {
00020   if ( theTimer != NULL ) {
00021     delete theTimer;
00022   }
00023 
00024   theTimer = this;
00025 
00026   memset( &event, 0, sizeof( event ) );
00027 
00028   // sched_get_priority_max( SCHED_RR ) == 63
00029 
00030   event.sigev_priority = fixprio( 63 ); // 25
00031 
00032   event.sigev_notify = SIGEV_SIGNAL;
00033   event.sigev_signo  = TimerSignal;
00034 
00035   memset( &t, 0, sizeof( t ) );
00036 
00037   t.it_value.tv_nsec    = nsec;
00038   t.it_interval.tv_nsec = nsec;
00039 
00040   t.it_value.tv_sec     = sec;
00041   t.it_interval.tv_sec  = sec;
00042    
00043   // create the timer, binding it to the event
00044 
00045   if ( timer_create( CLOCK_REALTIME, &event, &timerid ) == -1 )
00046   {
00047      MC_OnError( errno, Error, "while creating a timer." )
00048   }
00049 
00050   struct sigaction act;
00051   sigset_t set;
00052 
00053   sigemptyset( &set );
00054   sigaddset(   &set, TimerSignal );
00055 
00056   // Define a handler for TimerSignal
00057   act.sa_flags   = 0;
00058   act.sa_mask    = set;
00059   act.sa_handler = wrapper;
00060 
00061   sigaction( TimerSignal, &act, NULL );
00062 
00063 
00064 #if defined( __QNXNTO__ )
00065   last_cycles    = 0;
00066   current_cycles = 0;
00067   cpu_freq = SYSPAGE_ENTRY( qtime )->cycles_per_sec;
00068 
00069   clkper.nsec  = 999847;
00070   clkper.fract = 0;
00071 
00072   ClockPeriod( CLOCK_REALTIME, &clkper, NULL, 0 ); // ~1 ms
00073 #endif
00074 
00075 }

Timer::Timer ULONG    nsec,
ULONG    sec = 0
 

Timer::Timer ULONG    nsec = 0,
ULONG    sec = 0
[protected]
 


Member Function Documentation

__inline _uint64 Timer::getCycles   [protected]
 

__inline _uint64 Timer::getCycles   [protected]
 

Definition at line 92 of file Timer.cpp.

00092                                 {
00093   return ClockCycles();
00094 }

__inline double Timer::getElapsed _uint64    started [protected]
 

__inline double Timer::getElapsed _uint64    cycles [protected]
 

Definition at line 96 of file Timer.cpp.

00097 {
00098 
00099    // Put pulse validation here
00100    current_cycles = ClockCycles();
00101 
00102    // Could get rid of timer by using more clever timer setup
00103    elapsedCycles = ( current_cycles - cycles ) / cpu_freq;
00104 
00105    return elapsedCycles;
00106 }

__inline double Timer::getSpent   [protected]
 

__inline double Timer::getSpent   [protected]
 

Definition at line 108 of file Timer.cpp.

00108                               {
00109   timer_gettime( timerid, &t );
00110 
00111   register double dt = t.it_value.tv_nsec;
00112 
00113   dt /= 1000000000ul;
00114   dt += t.it_value.tv_sec;
00115 
00116   return dt;
00117 }

virtual void Timer::run   [protected, virtual]
 

Reimplemented from Basic_PThread.

virtual void Timer::run   [protected, virtual]
 

Reimplemented from Basic_PThread.

__inline void Timer::start  
 

Definition at line 78 of file Timer.cpp.

00078                          {
00079   // Increase concurrency level to number of CPU + 3
00080 
00081 #if (__sun) || (__SUN__)
00082 
00083     thr_setconcurrency( sysconf(_SC_NPROCESSORS_ONLN) + 3 );
00084 
00085 #endif
00086 
00087   startedTime = time( NULL );
00088 
00089   timer_settime( timerid, 0, &t, NULL );
00090 }

virtual void Timer::tick int    signo [protected, pure virtual]
 

virtual void Timer::tick int    signo [protected, pure virtual]
 

virtual void Timer::timedRun int    signo [pure virtual]
 

void Timer::wrapper int    signo [inline, static, protected]
 

Definition at line 68 of file Timer.hpp.

00069   {
00070     assert( signo == TimerSignal );
00071     theTimer->tick( signo ); 
00072   }

void Timer::wrapper int    signo [inline, static]
 

Definition at line 36 of file Timer.hpp.

00037   {
00038     theTimer->timedRun( signo ); 
00039   }

void Timer::wrapper int    signo [inline, static, protected]
 

Definition at line 68 of file Timer.hpp.

00069   {
00070     assert( signo == TimerSignal );
00071     theTimer->tick( signo ); 
00072   }


Member Data Documentation

const ULONG Timer::Period_100_ms = 100000000L
 

Definition at line 48 of file Timer.hpp.

const ULONG Timer::Period_10_ms = 10000000L
 

Definition at line 45 of file Timer.hpp.

const ULONG Timer::Period_1_ms = 1000000L
 

Definition at line 44 of file Timer.hpp.

const ULONG Timer::Period_20_ms = 20000000L
 

Definition at line 46 of file Timer.hpp.

const ULONG Timer::Period_250_ms = 250000000L
 

Definition at line 49 of file Timer.hpp.

const ULONG Timer::Period_500_ms = 500000000L
 

Definition at line 50 of file Timer.hpp.

const ULONG Timer::Period_50_ms = 50000000L
 

Definition at line 47 of file Timer.hpp.

const ULONG Timer::Period_750_ms = 750000000L
 

Definition at line 51 of file Timer.hpp.

struct sigevent Timer::event [private]
 

Definition at line 80 of file Timer.hpp.

struct sigevent Timer::event [private]
 

Definition at line 46 of file Timer.hpp.

struct sigevent Timer::event [private]
 

Definition at line 80 of file Timer.hpp.

struct itimerspec Timer::t [private]
 

Definition at line 81 of file Timer.hpp.

struct itimerspec Timer::t [private]
 

Definition at line 47 of file Timer.hpp.

struct itimerspec Timer::t [private]
 

Definition at line 81 of file Timer.hpp.

Timer* Timer::theTimer [static, protected]
 

Definition at line 55 of file Timer.hpp.

Timer * Timer::theTimer = NULL [static, protected]
 

Definition at line 15 of file Timer.cpp.

clockid_t Timer::timerid [private]
 

Definition at line 79 of file Timer.hpp.


The documentation for this class was generated from the following files:
Generated on Sun Oct 14 18:50:15 2001 for Standard J2K Library by doxygen1.2.11.1 written by Dimitri van Heesch, © 1997-2001