timer Class Reference

Implements a timeout mechanism via sigalarm. More...

Public Member Functions

 ClassName ("timer")
 Declare name of the class and its debug switch. More...
 
 timer (unsigned int seconds)
 Construct with specified time-out, a value of 0 makes it a no-op. More...
 
 ~timer ()
 Destructor. Restores the alarm and signal handler as required. More...
 
 ClassName ("timer")
 Declare name of the class and its debug switch. More...
 
 timer (unsigned int seconds)
 Construct with specified time-out, a value of 0 makes it a no-op. More...
 
 ~timer ()
 Destructor. Restores the alarm and signal handler as required. More...
 

Public Attributes

unsigned int timeOut_
 The time-out value (seconds). Needed by macro timedOut. More...
 

Static Public Attributes

static jmp_buf envAlarm
 State for setjmp. Needed by macro timedOut. More...
 

Detailed Description

Implements a timeout mechanism via sigalarm.

Example usage:

timer myTimer(5); // 5 sec
..
if (timedOut(myTimer))
{
// timed out
}
else
{
// do something possible blocking
}
#define timedOut(x)
Check if timeout has occurred.
Definition: timer.H:73
Implements a timeout mechanism via sigalarm.
Definition: timer.H:84

Constructor set signal handler on sigalarm and alarm(). Destructor clears these.

Warning
The setjmp restores complete register state so including local vars held in regs. So if in blocking part something gets calced in a stack based variable make sure it is declared 'volatile'.
Note
timedOut is macro because setjmp can't be in member function of timer. ?something to do with stack frames.
Source files

Example usage:

timer myTimer(5); // 5 sec
..
if (timedOut(myTimer))
{
// timed out
}
else
{
// do something possible blocking
}

Constructor set signal handler on sigalarm and alarm(). Destructor clears these.

Warning
The setjmp restores complete register state so including local vars held in regs. So if in blocking part something gets calced in a stack based variable make sure it is declared 'volatile'.
Note
timedOut is macro because setjmp can't be in member function of timer. ?something to do with stack frames.
Source files

Definition at line 83 of file timer.H.

Constructor & Destructor Documentation

◆ timer() [1/2]

timer ( unsigned int  seconds)

Construct with specified time-out, a value of 0 makes it a no-op.

Definition at line 80 of file timer.C.

References Foam::abort(), DebugInFunction, Foam::endl(), Foam::FatalError, FatalErrorInFunction, hTimer_, Foam::MSwindows::lastError(), Foam::nl, Foam::setHandler(), SIGALRM, timer::timeOut_, and timerExpired().

Here is the call graph for this function:

◆ ~timer() [1/2]

~timer ( )

Destructor. Restores the alarm and signal handler as required.

Definition at line 129 of file timer.C.

References Foam::abort(), DebugInFunction, Foam::endl(), Foam::FatalError, FatalErrorInFunction, hTimer_, Foam::MSwindows::lastError(), Foam::nl, Foam::resetHandler(), and SIGALRM.

Here is the call graph for this function:

◆ timer() [2/2]

timer ( unsigned int  seconds)
explicit

Construct with specified time-out, a value of 0 makes it a no-op.

◆ ~timer() [2/2]

~timer ( )

Destructor. Restores the alarm and signal handler as required.

Member Function Documentation

◆ ClassName() [1/2]

ClassName ( "timer"  )

Declare name of the class and its debug switch.

◆ ClassName() [2/2]

ClassName ( "timer"  )

Declare name of the class and its debug switch.

Member Data Documentation

◆ timeOut_

unsigned int timeOut_

The time-out value (seconds). Needed by macro timedOut.

Definition at line 105 of file timer.H.

Referenced by timer::timer().

◆ envAlarm

static jmp_buf envAlarm
static

State for setjmp. Needed by macro timedOut.

Definition at line 108 of file timer.H.


The documentation for this class was generated from the following files: