FreeFOAM The Cross-Platform CFD Toolkit
timer Class Reference

Implements a timeout mechanism via sigalarm. More...

#include <OSspecific/timer.H>


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 82 of file timer.H.

List of all members.

Public Member Functions

 ClassName ("timer")
 Declare name of the class and its debug switch.
 timer (const unsigned int newTimeOut)
 Construct from components.
 ~timer ()

Public Attributes

unsigned int newTimeOut_
 current time out value. Needed by macro timedOut

Static Public Attributes

static jmp_buf envAlarm
 state for setjmp. Needed by macro timedOut

Constructor & Destructor Documentation

timer ( const unsigned int  newTimeOut)

Construct from components.

newTimeOut=0 makes it do nothing.

Definition at line 60 of file timer.C.

References Foam::abort(), Foam::endl(), Foam::FatalError, FatalErrorIn, Foam::Info, and timer::newTimeOut_.

~timer ( )

Definition at line 110 of file timer.C.

References Foam::abort(), Foam::endl(), Foam::FatalError, FatalErrorIn, and Foam::Info.


Member Function Documentation

ClassName ( "timer"  )

Declare name of the class and its debug switch.


Member Data Documentation

unsigned int newTimeOut_

current time out value. Needed by macro timedOut

Definition at line 107 of file timer.H.

Referenced by timer::timer().

jmp_buf envAlarm
static

state for setjmp. Needed by macro timedOut

Definition at line 110 of file timer.H.


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