Loading...
Searching...
No Matches
timer Class Reference

Implements a timeout mechanism via sigalarm. More...

#include <timer.H>

Public Member Functions

 timer (unsigned int seconds)
 Construct with specified time-out, a value of 0 makes it a no-op.
 ~timer ()
 Destructor. Restores the alarm and signal handler as required.

Public Attributes

unsigned int timeOut_
 The time-out value (seconds). Needed by macro timedOut.

Static Public Attributes

static int debug
 Named/registered debug switch: 'timer'.
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
}
timer(unsigned int seconds)
Construct with specified time-out, a value of 0 makes it a no-op.
#define timedOut(x)
Check if timeout has occurred.
Definition timer.H:72

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

Construct with specified time-out, a value of 0 makes it a no-op.

◆ ~timer()

~timer ( )

Destructor. Restores the alarm and signal handler as required.

Member Data Documentation

◆ debug

int debug
static

Named/registered debug switch: 'timer'.

Definition at line 107 of file timer.H.

◆ timeOut_

unsigned int timeOut_

The time-out value (seconds). Needed by macro timedOut.

Definition at line 112 of file timer.H.

◆ envAlarm

jmp_buf envAlarm
static

State for setjmp. Needed by macro timedOut.

Definition at line 117 of file timer.H.


The documentation for this class was generated from the following file:
  • src/OSspecific/POSIX/signals/timer.H