OpenFOAM logo
The Open Source CFD Toolbox
  Source Guide OpenCFD Solutions Contact OpenFOAM

timer Class Reference

Implements a timeout mechanism via sigalarm. More...

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

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


Constructor & Destructor Documentation

timer ( const unsigned int  newTimeOut  ) 

Construct from components.

newTimeOut=0 makes it do nothing.

Definition at line 53 of file timer.C.

~timer (  ) 

Definition at line 103 of file timer.C.


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

jmp_buf envAlarm [static]

state for setjmp. Needed by macro timedOut

Definition at line 107 of file timer.H.


The documentation for this class was generated from the following files:
Copyright © 2000-2009 OpenCFD Ltd