RTP Trace System
1.0
|
#include <timedthread.h>
Public Member Functions | |
TimedThread (const card64 usec, const cardinal flags=ThreadCancelAsynchronous) | |
~TimedThread () | |
card64 | getInterval () const |
void | setInterval (const card64 usec) |
cardinal | getTimerCorrection () const |
void | setTimerCorrection (const cardinal maxCorrection=0) |
void | leaveCorrectionLoop () |
void | setFastStart (const bool on) |
bool | getFastStart () const |
void | stop () |
bool | pendingTimerEvent () const |
Protected Member Functions | |
virtual void | timerEvent ()=0 |
Private Member Functions | |
void | run () |
Private Attributes | |
card64 | Interval |
cardinal | TimerCorrection |
bool | AlarmHandlerInitialized |
bool | FastStart |
bool | NewInterval |
bool | LeaveCorrectionLoop |
Timed Thread.
This abstract class realizes a timed thread based on Thread. The user of this class has to implement timerEvent(). Inaccurate system timers are corrected by calling user's timerEvent() implementation multiple times if necessary. This feature can be modified by setTimerCorrection (Default is on at a maximum of 10 calls). IMPORTANT: Do *not* use Thread methods within async signal handlers. This may cause deadlocks. See PThread's pthread_mutex_lock man-page, section "Async Signal Safety" for more information!
Coral::TimedThread::TimedThread | ( | const card64 | usec, |
const cardinal | flags = ThreadCancelAsynchronous |
||
) |
Constructor. A new timed thread with a given interval will be created but *not* started! To start the new thread, call start(). The interval gives the time for the interval in microseconds, the virtual function timerEvent() is called. The default timer correction is set to 10. See setTimerCorrection() for more information on timer correction. The first call of timerEvent() will be made immediately, if the fast start option is set (default). Otherwise it will be made after the given interval.
usec | Interval in microseconds. |
flags | Thread flags |
Destructor.
bool Coral::TimedThread::getFastStart | ( | ) | const [inline] |
Get fast start option: If false, the first call of timerEvent() will be made *after* the given interval; otherwise it will be made immediately.
card64 Coral::TimedThread::getInterval | ( | ) | const [inline] |
Get timed thread's interval.
cardinal Coral::TimedThread::getTimerCorrection | ( | ) | const [inline] |
Get maxCorrection value for inaccurate system timer.
void Coral::TimedThread::leaveCorrectionLoop | ( | ) | [inline] |
Leave timer correction loop: If the thread is in a timer correction loop, the loop will be finished after the current timerEvent() call returns.
bool Coral::TimedThread::pendingTimerEvent | ( | ) | const [inline] |
Check for pending timer event(). This can be used to check for a pending timer event() (SIGALRM signal) within the current timerEvent() run.
void Coral::TimedThread::run | ( | ) | [private, virtual] |
The virtual run() method, which contains the thread's implementation. It has to be implemented by classes, which inherit Thread.
Implements Coral::Thread.
void Coral::TimedThread::setFastStart | ( | const bool | on | ) | [inline] |
Set fast start option: If false, the first call of timerEvent() will be made *after* the given interval; otherwise it will be made immediately. The default is true.
on | true, to set option; false otherwise. |
void Coral::TimedThread::setInterval | ( | const card64 | usec | ) |
Set timed thread's interval.
usec | Interval in microseconds. |
void Coral::TimedThread::setTimerCorrection | ( | const cardinal | maxCorrection = 0 | ) | [inline] |
Set correction of inaccurate system timer to given value. This on will cause the timerEvent() function to be called a maximum of maxCorrection times, if the total number of calls is lower than the calculated number of times the function should have been called. If the number of correction calls is higher than maxCorrection, *no* correction will be done! Default is 0, which turns correction off.
of | true to activate correction; false to deactivate. |
void Coral::TimedThread::stop | ( | ) | [virtual] |
Reimplementation of stop().
Reimplemented from Coral::Thread.
Reimplemented in Coral::RTCPAbstractServer.
virtual void Coral::TimedThread::timerEvent | ( | ) | [protected, pure virtual] |
The virtual timerEvent() method, which contains the timed thread's implementation. It has to be implemented by classes, which inherit TimedThread. This method is called regularly with the given interval.
Implemented in Coral::BandwidthManager, Coral::RTPSender, Coral::RTCPAbstractServer, Coral::RoundTripTimePinger, Coral::RTCPSender, Coral::TrafficShaperSingleton, and SenderThread.
bool Coral::TimedThread::AlarmHandlerInitialized [private] |
bool Coral::TimedThread::FastStart [private] |
card64 Coral::TimedThread::Interval [private] |
bool Coral::TimedThread::LeaveCorrectionLoop [private] |
bool Coral::TimedThread::NewInterval [private] |
cardinal Coral::TimedThread::TimerCorrection [private] |