ddc
List of all members
ddcThread Class Referenceabstract

generic pthread wrapper class More...

#include <ddcThread.h>

Inheritance diagram for ddcThread:
Inheritance graph
[legend]

Public Member Functions

Constructors etc.
 ddcThread ()
 
virtual ~ddcThread ()
 
Accessors
pthread_t self () const
 get current thread-id More...
 
virtual std::string toString () const
 get string representation of the current thread More...
 
pthread_attr_t * attr () const
 get current thread attributes (for use by child classes) More...
 
int running () const
 get value of m_running flag More...
 
int detached () const
 get value of m_detached flag More...
 
Generic API
virtual void init ()
 
virtual int start ()
 
virtual int join ()
 
virtual int detach (bool force=false)
 
virtual void * run ()=0
 

Protected Attributes

Administrivia
pthread_t m_tid
 underlying thread handle More...
 
pthread_attr_t * m_attr
 underlying thread attributes (NULL by default) More...
 
int m_running
 is this thread is currently running? More...
 
int m_detached
 is this thread currently detached? More...
 

Detailed Description

generic pthread wrapper class

Constructor & Destructor Documentation

◆ ddcThread()

ddcThread::ddcThread ( )
inline

Default constructor

◆ ~ddcThread()

ddcThread::~ddcThread ( )
virtual

Default destructor

  • detaches thread via pthread_detach() if running and not already detached
  • if thread is flagged as running, it will be cancelled via pthread_cancel()

Member Function Documentation

◆ self()

pthread_t ddcThread::self ( ) const
inline

get current thread-id

◆ toString()

std::string ddcThread::toString ( void  ) const
virtual

get string representation of the current thread

◆ attr()

pthread_attr_t* ddcThread::attr ( ) const
inline

get current thread attributes (for use by child classes)

◆ running()

int ddcThread::running ( ) const
inline

get value of m_running flag

◆ detached()

int ddcThread::detached ( ) const
inline

get value of m_detached flag

◆ init()

virtual void ddcThread::init ( )
inlinevirtual

called by default start() to initalize m_attr.

  • default does nothing

◆ start()

int ddcThread::start ( )
virtual

calls pthread_create() to create the thread; sets m_running=true

  • default implementation also de-initializes m_attr via pthread_attr_destroy() if it is non-NULL

References ddcThreadRun().

Referenced by CDDCServerThreadPool::CDDCServerThreadPool().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ join()

int ddcThread::join ( )
virtual

attempt to pthread_join() the current thread iff it is running.

  • blocks until thread has completed
  • if successful, thread is marked as detached
    Returns
    ENOTSUP if thread is not running, otherwise as for pthread_join()

◆ detach()

int ddcThread::detach ( bool  force = false)
virtual

attempt to pthread_detach() the current thread iff it is running and not detached.

  • call if you don't want to wait for the thread to complete.
  • on success, thread is flagged as detached.
    Parameters
    forceif true, thread will be flagged as not running. in this case, the underlying pthread may outlive the ddcThread wrapper object, and its run() method should terminate by calling pthread_exit().
    Returns
    ENOTSUP if thread is not running, otherwise as for pthread_detach()

◆ run()

virtual void* ddcThread::run ( )
pure virtual

code to execute inside the newly created thread after start()

  • derived clases must override this method
    Returns
    void* as expected by pthread_create routines

Implemented in CDDCServerThread.

Member Data Documentation

◆ m_tid

pthread_t ddcThread::m_tid
protected

underlying thread handle

◆ m_attr

pthread_attr_t* ddcThread::m_attr
protected

underlying thread attributes (NULL by default)

◆ m_running

int ddcThread::m_running
protected

is this thread is currently running?

◆ m_detached

int ddcThread::m_detached
protected

is this thread currently detached?


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