Public Member Functions | Data Fields | Static Public Attributes | Static Private Member Functions | Static Private Attributes
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...
 

Data Fields

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...
 

Static Private Member Functions

static void signalHandler (int)
 Alarm handler. More...
 

Static Private Attributes

static struct sigaction oldAction_
 Old signal masks. More...
 
static unsigned int oldTimeOut_ = 0
 Old alarm() value. 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 60 of file timer.C.

References Foam::abort(), Foam::endl(), Foam::FatalError, FatalErrorInFunction, Foam::Info, timer::newTimeOut_, timer::oldAction_, timer::oldTimeOut_, and timer::signalHandler().

Here is the call graph for this function:

◆ ~timer()

~timer ( )

Destructor.

Definition at line 106 of file timer.C.

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

Here is the call graph for this function:

Member Function Documentation

◆ signalHandler()

void signalHandler ( int  )
staticprivate

Alarm handler.

Definition at line 47 of file timer.C.

References Foam::endl(), and Foam::Info.

Referenced by timer::timer().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ClassName()

ClassName ( "timer"  )

Declare name of the class and its debug switch.

Field Documentation

◆ oldAction_

struct sigaction oldAction_
staticprivate

Old signal masks.

Definition at line 86 of file timer.H.

Referenced by timer::timer().

◆ oldTimeOut_

unsigned int oldTimeOut_ = 0
staticprivate

Old alarm() value.

Definition at line 89 of file timer.H.

Referenced by timer::timer().

◆ newTimeOut_

unsigned int newTimeOut_

Current time out value. Needed by macro timedOut.

Definition at line 106 of file timer.H.

Referenced by 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:
timedOut
#define timedOut(x)
Check it a timeout has occured.
Definition: timer.H:71
Foam::timer::timer
timer(const unsigned int newTimeOut)
Construct from components.
Definition: timer.C:60