RTP Audio System  2.0.0
Thread Class Reference

Thread. More...

#include <thread.h>

Inheritance diagram for Thread:
Synchronizable AudioDevice MediaServent MultiTimerThread< Timers > RTCPReceiver RTPReceiver TestReceiver VerificationClientThread AlphaServent TimedThread AbstractMediaServer AdvancedAudioDecoder BandwidthManager RoundTripTimePinger RTCPAbstractServer RTCPSender RTPSender TrafficShaperSingleton

List of all members.

Public Member Functions

 Thread (const char *name="Thread", const cardinal flags=TF_CancelDeferred)
virtual ~Thread ()
bool running () const
pid_t getPID () const
virtual bool start (const char *name=NULL)
virtual void * stop ()
void * join ()
virtual void cancel ()

Static Public Member Functions

static card64 delay (const card64 delayTimeout, const bool interruptable=false)
static cardinal setCancelState (const cardinal state)

Static Public Attributes

static const cardinal TF_CancelAsynchronous = 0
static const cardinal TF_CancelDeferred = (1 << 0)
static const cardinal TCS_CancelEnabled = PTHREAD_CANCEL_ENABLE
static const cardinal TCS_CancelDisabled = PTHREAD_CANCEL_DISABLE
static const cardinal TCS_CancelDeferred = PTHREAD_CANCEL_DEFERRED

Protected Member Functions

virtual void testCancel ()
virtual void run ()=0

Static Protected Member Functions

static void exit (void *result=NULL)
static void yield ()

Protected Attributes

pthread_t PThread
pid_t PID

Static Private Member Functions

static void * go (void *argument)

Private Attributes

cardinal Flags
pthread_mutex_t StartupMutex
pthread_cond_t StartupCondition

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

Thread::Thread ( const char *  name = "Thread",
const cardinal  flags = TF_CancelDeferred 
)

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

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

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


Member Function Documentation

void Thread::cancel ( ) [virtual]

Cancel the thread.

Reimplemented in MultiTimerThread< Timers >.

card64 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 Thread::exit ( void *  result = NULL) [inline, static, protected]

Exit current thread.

Parameters:
resultResult to return.
pid_t Thread::getPID ( ) const [inline]

Get thread's PID.

void * Thread::go ( void *  argument) [static, private]
void * Thread::join ( )

Wait for the thread to be finished.

Returns:
Return value from joined thread.
virtual void 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 TestReceiver, MediaServent, MultiTimerThread< Timers >, AudioDevice, RTPReceiver, RTCPReceiver, and VerificationClientThread.

bool Thread::running ( ) const [inline]

Check, if the thread is running.

Returns:
true, if the thread is running, false otherwise
static cardinal Thread::setCancelState ( const cardinal  state) [inline, static]

Enable or disable cancelability of calling thread. The previous state is returned. Important note: The result may include additional state information, depending on the operating system. This state can be restored by giving this complete information to a setCancelState() call.

Parameters:
enabledTCS_CancelEnable to enable cancellation; TCS_CancelDisable otherwise.
Returns:
Old state.
bool Thread::start ( const char *  name = NULL) [virtual]

Start the thread, if not already started.

Parameters:
nameThread name (NULL for default).
Returns:
true, if the thread has been started; false, if not.
void * 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
Returns:
Return value from stopped thread.

Reimplemented in AbstractMediaServer, MultiTimerThread< Timers >, RTCPAbstractServer, and VerificationClientThread.

void Thread::testCancel ( ) [protected, virtual]

Test for cancellation. If the thread received a cancel signal, it will be cancelled.

static void 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

pid_t Thread::PID [protected]
pthread_t Thread::PThread [protected]
pthread_cond_t Thread::StartupCondition [private]
pthread_mutex_t Thread::StartupMutex [private]
const cardinal Thread::TCS_CancelDeferred = PTHREAD_CANCEL_DEFERRED [static]
const cardinal Thread::TCS_CancelDisabled = PTHREAD_CANCEL_DISABLE [static]
const cardinal Thread::TCS_CancelEnabled = PTHREAD_CANCEL_ENABLE [static]
const cardinal Thread::TF_CancelDeferred = (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