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 (const unsigned int newTimeOut)
 Construct from components. More...
 
 ~timer ()
 Destructor. More...
 

Public Attributes

unsigned int newTimeOut_
 Current time out value. 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
}

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

timedOut is macro because setjmp can't be in member function of timer. ?something to do with stack frames.

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'.
Source files

Definition at line 81 of file timer.H.

Constructor & Destructor Documentation

◆ timer()

timer ( const unsigned int  newTimeOut)

Construct from components.

newTimeOut=0 makes it do nothing.

Definition at line 59 of file timer.C.

References Foam::abort(), Foam::endl(), Foam::FatalError, FatalErrorInFunction, InfoInFunction, and timer::newTimeOut_.

Here is the call graph for this function:

◆ ~timer()

~timer ( )

Destructor.

Definition at line 105 of file timer.C.

References Foam::abort(), Foam::endl(), Foam::FatalError, FatalErrorInFunction, InfoInFunction, and timer::newTimeOut_.

Here is the call graph for this function:

Member Function Documentation

◆ ClassName()

ClassName ( "timer"  )

Declare name of the class and its debug switch.

Member Data Documentation

◆ newTimeOut_

unsigned int newTimeOut_

Current time out value. Needed by macro timedOut.

Definition at line 106 of file timer.H.

Referenced by timer::timer(), and timer::~timer().

◆ envAlarm

jmp_buf envAlarm
static

State for setjmp. Needed by macro timedOut.

Definition at line 109 of file timer.H.


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