RTP Trace System  1.0
Coral::Thread Class Reference

Thread. More...

#include <thread.h>

Inheritance diagram for Coral::Thread:
Coral::Synchronizable Coral::RTCPReceiver Coral::RTPReceiver Coral::TimedThread VerificationClientThread Coral::BandwidthManager Coral::RoundTripTimePinger Coral::RTCPAbstractServer Coral::RTCPSender Coral::RTPSender Coral::TrafficShaperSingleton SenderThread Coral::TraceServer

List of all members.

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

Detailed Description

Thread.

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!

Author:
Thomas Dreibholz
Version:
1.0
See also:
Synchronizable

Constructor & Destructor Documentation

Constructor. A new thread will be created but *not* started! To start the new thread, call start().

Parameters:
flagsFlags for the thread to be created
See also:
start
Coral::Thread::~Thread ( ) [virtual]

Destructor. The thread will be stopped (if running) and deleted.


Member Function Documentation

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.

Parameters:
delayTimeTimeout in microseconds.
interruptabletrue, if delay may be interrupted by signals; false otherwise.
Returns:
Remaining delay, if interrupted; 0 otherwise.
static void Coral::Thread::exit ( const cardinal  result = 0) [inline, static, protected]

Exit current thread.

Parameters:
resultResult 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.

Returns:
true, if the thread is running, false otherwise
bool Coral::Thread::start ( ) [virtual]

Start the thread, if not already started.

Returns:
true, if the thread has been started; false, if not.
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.

See also:
testCancel

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!!!

See also:
testSuspension
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.

Returns:
true, if the thread was 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.


Member Data Documentation

pthread_t Coral::Thread::PThread [protected]
pthread_mutex_t Coral::Thread::SuspensionMutex [private]
const cardinal Coral::Thread::ThreadCancelDeferred = (1 << 0) [static]

The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines