RTP Trace System
1.0
|
#include <thread.h>
Public Member Functions | |
Thread (const cardinal flags=ThreadCancelAsynchronous) | |
virtual | ~Thread () |
bool | running () const |
virtual bool | start () |
virtual void | stop () |
cardinal | join () |
virtual void | cancel () |
virtual void | suspend () |
virtual void | resume () |
Static Public Member Functions | |
static card64 | delay (const card64 delayTimeout, const bool interruptable=false) |
Static Public Attributes | |
static const cardinal | ThreadCancelAsynchronous = 0 |
static const cardinal | ThreadCancelDeferred = (1 << 0) |
Protected Member Functions | |
virtual void | testCancel () |
virtual bool | testSuspension () |
virtual void | run ()=0 |
Static Protected Member Functions | |
static void | exit (const cardinal result=0) |
static void | yield () |
Protected Attributes | |
pthread_t | PThread |
Static Private Member Functions | |
static void * | go (void *i) |
Private Attributes | |
pthread_mutex_t | SuspensionMutex |
cardinal | Flags |
bool | IsSuspended |
This abstract class realizes threads based on Linux's pthreads. The user of this class has to implement run(). Synchronization is implemented by inheriting Synchronizable. 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::Thread::Thread | ( | const cardinal | flags = ThreadCancelAsynchronous | ) |
Coral::Thread::~Thread | ( | ) | [virtual] |
Destructor. The thread will be stopped (if running) and deleted.
void Coral::Thread::cancel | ( | ) | [virtual] |
Cancel the thread.
card64 Coral::Thread::delay | ( | const card64 | delayTimeout, |
const bool | interruptable = false |
||
) | [static] |
Delay execution of current thread for a given timeout. This function uses nanosleep(), so no signals are affected.
delayTime | Timeout in microseconds. |
interruptable | true, if delay may be interrupted by signals; false otherwise. |
static void Coral::Thread::exit | ( | const cardinal | result = 0 | ) | [inline, static, protected] |
Exit current thread.
result | Result to return. |
void * Coral::Thread::go | ( | void * | i | ) | [static, private] |
Wait for the thread to be finished.
void Coral::Thread::resume | ( | ) | [virtual] |
Resume a suspended thread.
virtual void Coral::Thread::run | ( | ) | [protected, pure virtual] |
The virtual run() method, which contains the thread's implementation. It has to be implemented by classes, which inherit Thread.
Implemented in Coral::RTPReceiver, Coral::TimedThread, Coral::RTCPReceiver, and VerificationClientThread.
bool Coral::Thread::running | ( | ) | const [inline] |
Check, if the thread is running.
bool Coral::Thread::start | ( | ) | [virtual] |
Start the thread, if not already started.
void Coral::Thread::stop | ( | ) | [virtual] |
Stop the thread, if not already stopped. If the thread flag ThreadCancelAsynchronous is set, it will be stopped immediately. If the flag ThreadCancelDeferred is set, it will be stopped when a cancellation point is reached (-> see pthreads documentation). testCancel() is such a cancellation point.
Reimplemented in Coral::RTCPAbstractServer, Coral::TimedThread, and VerificationClientThread.
void Coral::Thread::suspend | ( | ) | [virtual] |
Suspend the thread. Note: The thread will not be suspended immediately! The thread will be suspended, when it reaches the next testSuspension() call! => To implement suspendable threads, testSuspension() must be called by the thread regularly!!!
void Coral::Thread::testCancel | ( | ) | [protected, virtual] |
Test for cancellation. If the thread received a cancel signal, it will be cancelled.
bool Coral::Thread::testSuspension | ( | ) | [protected, virtual] |
Test for suspension. If the thread received a suspension signal, it will be suspended.
static void Coral::Thread::yield | ( | ) | [inline, static, protected] |
Voluntarily move current thread to end of queue of threads waiting for CPU time (sched_yield() call). This will result in scheduling to next waiting thread, if there is any.
cardinal Coral::Thread::Flags [private] |
bool Coral::Thread::IsSuspended [private] |
pthread_t Coral::Thread::PThread [protected] |
pthread_mutex_t Coral::Thread::SuspensionMutex [private] |
const cardinal Coral::Thread::ThreadCancelAsynchronous = 0 [static] |
const cardinal Coral::Thread::ThreadCancelDeferred = (1 << 0) [static] |