Public Member Functions | Public Attributes | Static Public Attributes | List of all members
timer Class Reference

Implements a timeout mechanism via sigalarm. More...

Public Member Functions

 ClassName ("timer")
 
 timer (unsigned int seconds)
 
 ~timer ()
 

Public Attributes

unsigned int timeOut_
 

Static Public Attributes

static jmp_buf envAlarm
 

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.

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

Constructor & Destructor Documentation

◆ timer()

timer ( unsigned int  seconds)
explicit

Definition at line 55 of file timer.C.

References Foam::abort(), DebugInFunction, Foam::endl(), Foam::FatalError, FatalErrorInFunction, Foam::setHandler(), and timer::timeOut_.

Here is the call graph for this function:

◆ ~timer()

~timer ( )

Definition at line 89 of file timer.C.

References DebugInFunction, Foam::endl(), and Foam::resetHandler().

Here is the call graph for this function:

Member Function Documentation

◆ ClassName()

ClassName ( "timer"  )

Member Data Documentation

◆ timeOut_

unsigned int timeOut_

Definition at line 104 of file timer.H.

Referenced by timer::timer().

◆ envAlarm

jmp_buf envAlarm
static

Definition at line 107 of file timer.H.


The documentation for this class was generated from the following files:
Foam::timer::timer
timer(unsigned int seconds)
Definition: timer.C:55
timedOut
#define timedOut(x)
Definition: timer.H:72