reSIProcate
SIP stack, Dialog Usage Manager and related libraries
Loading...
Searching...
No Matches
resip::ThreadIf Class Referenceabstract

A wrapper class to create and spawn a thread. More...

#include <ThreadIf.hxx>

Inheritance diagram for resip::ThreadIf:
[legend]

Public Types

typedef std::thread::id Id
 
typedef pthread_key_t TlsKey
 
typedef void TlsDestructor(void *)
 

Public Member Functions

 ThreadIf ()
 
virtual ~ThreadIf ()
 
virtual void run ()
 
void join ()
 
void detach ()
 
virtual void shutdown ()
 
virtual bool waitForShutdown (int ms) const
 
bool isShutdown () const
 
virtual void thread ()=0
 

Static Public Member Functions

static Id selfId ()
 
static int tlsKeyCreate (TlsKey &key, TlsDestructor *destructor)
 This function follows pthread_key_create() signature.
 
static int tlsKeyDelete (TlsKey key)
 This function follows pthread_key_delete() signature.
 
static int tlsSetValue (TlsKey key, const void *val)
 This function follows pthread_setspecific() signature.
 
static void * tlsGetValue (TlsKey key)
 This function follows pthread_getspecific() signature.
 

Protected Attributes

std::shared_ptr< std::thread > mThreadObj
 
Id mId
 
bool mShutdown
 
Mutex mShutdownMutex
 
Condition mShutdownCondition
 

Detailed Description

A wrapper class to create and spawn a thread.


It is a base class. ThreadIf::thread() is a pure virtual method .

To use this class, derive from it and override the thread() method. To start the thread, call the run() method. The code in thread() will run in a separate thread.

Call shutdown() from the constructing thread to shut down the code. This will set the bool shutdown_ to true. The code in thread() should react properly to shutdown_ being set, by returning. Call join() to join the code.

Sample:

DerivedThreadIf thread;
thread.run();
// ... do stuff ...
thread.shutdown();
thread.join();
virtual void thread()=0

Definition at line 53 of file ThreadIf.hxx.

Member Typedef Documentation

◆ Id

typedef std::thread::id resip::ThreadIf::Id

Definition at line 79 of file ThreadIf.hxx.

◆ TlsDestructor

typedef void resip::ThreadIf::TlsDestructor(void *)

Definition at line 87 of file ThreadIf.hxx.

◆ TlsKey

typedef pthread_key_t resip::ThreadIf::TlsKey

Definition at line 85 of file ThreadIf.hxx.

Constructor & Destructor Documentation

◆ ThreadIf()

ThreadIf::ThreadIf ( )

Definition at line 59 of file ThreadIf.cxx.

◆ ~ThreadIf()

ThreadIf::~ThreadIf ( )
virtual

Definition at line 68 of file ThreadIf.cxx.

Member Function Documentation

◆ detach()

void ThreadIf::detach ( )

Definition at line 116 of file ThreadIf.cxx.

◆ isShutdown()

bool ThreadIf::isShutdown ( ) const

Definition at line 212 of file ThreadIf.cxx.

◆ join()

void ThreadIf::join ( )

Definition at line 92 of file ThreadIf.cxx.

◆ run()

void ThreadIf::run ( )
virtual

Definition at line 75 of file ThreadIf.cxx.

◆ selfId()

ThreadIf::Id ThreadIf::selfId ( )
static

Definition at line 124 of file ThreadIf.cxx.

◆ shutdown()

◆ thread()

◆ tlsGetValue()

void * ThreadIf::tlsGetValue ( TlsKey  key)
static

This function follows pthread_getspecific() signature.

Definition at line 179 of file ThreadIf.cxx.

◆ tlsKeyCreate()

int ThreadIf::tlsKeyCreate ( TlsKey &  key,
TlsDestructor *  destructor 
)
static

This function follows pthread_key_create() signature.

Definition at line 130 of file ThreadIf.cxx.

◆ tlsKeyDelete()

int ThreadIf::tlsKeyDelete ( TlsKey  key)
static

This function follows pthread_key_delete() signature.

Definition at line 150 of file ThreadIf.cxx.

◆ tlsSetValue()

int ThreadIf::tlsSetValue ( TlsKey  key,
const void *  val 
)
static

This function follows pthread_setspecific() signature.

Definition at line 169 of file ThreadIf.cxx.

◆ waitForShutdown()

bool ThreadIf::waitForShutdown ( int  ms) const
virtual

Definition at line 201 of file ThreadIf.cxx.

Member Data Documentation

◆ mId

Id resip::ThreadIf::mId
protected

Definition at line 118 of file ThreadIf.hxx.

◆ mShutdown

bool resip::ThreadIf::mShutdown
protected

Definition at line 120 of file ThreadIf.hxx.

◆ mShutdownCondition

Condition resip::ThreadIf::mShutdownCondition
mutableprotected

Definition at line 122 of file ThreadIf.hxx.

◆ mShutdownMutex

Mutex resip::ThreadIf::mShutdownMutex
mutableprotected

Definition at line 121 of file ThreadIf.hxx.

◆ mThreadObj

std::shared_ptr<std::thread> resip::ThreadIf::mThreadObj
protected

Definition at line 105 of file ThreadIf.hxx.


The documentation for this class was generated from the following files: