Mixes for Privacy and Anonymity in the Internet
Public Member Functions | Static Public Member Functions | Private Attributes | Static Private Attributes | List of all members

This class could be used for creating a new thread.
More...

Public Member Functions

 CAThread ()
 Creates a CAThread object but no actual thread. More...
 
 CAThread (const UINT8 *strName)
 Creates a CAThread object but no actual thread. More...
 
 ~CAThread ()
 
SINT32 setMainLoop (THREAD_MAIN_TYP fnc)
 Sets the main function which will be executed within this thread. More...
 
SINT32 start (void *param, bool bDaemon=false, bool bSilent=false)
 Starts the execution of the main function of this thread. More...
 
SINT32 join ()
 Waits for the main function to finish execution. More...
 
UINT8getName () const
 
UINT32 getID () const
 

Static Public Member Functions

static thread_id_t getSelfID ()
 

Private Attributes

THREAD_MAIN_TYP m_fncMainLoop
 
pthread_t * m_pThread
 
UINT8m_strName
 
UINT32 m_Id
 

Static Private Attributes

static UINT32 ms_LastId =0
 

Detailed Description

This class could be used for creating a new thread.

The function which should be executed within this thread could be set be using the setMainLoop() method.

Some example on using CAThread:

First one needs to define a function which should be executed within the thread:

THREAD_RETURN doSomeThing(void* param)
{
}

Now we can create the thread, set the main function, start the thread and wait for the thread to finish execution:

CAThread* pThread=new CAThread();
pThread->setMainLoop(doSomeThing);
pThread->start(theParams);
pThread->join();
delete pThread;

Constructor & Destructor Documentation

◆ CAThread() [1/2]

CAThread::CAThread ( )

Creates a CAThread object but no actual thread.

References m_fncMainLoop, m_Id, m_pThread, m_strName, and ms_LastId.

◆ CAThread() [2/2]

CAThread::CAThread ( const UINT8 strName)

Creates a CAThread object but no actual thread.

Parameters
strNamea name for this thread, useful mostly for debugging

References len, m_fncMainLoop, m_Id, m_pThread, m_strName, and ms_LastId.

◆ ~CAThread()

CAThread::~CAThread ( )

Member Function Documentation

◆ getID()

UINT32 CAThread::getID ( ) const

◆ getName()

UINT8* CAThread::getName ( ) const

◆ getSelfID()

static thread_id_t CAThread::getSelfID ( )
static

◆ join()

SINT32 CAThread::join ( )

◆ setMainLoop()

SINT32 CAThread::setMainLoop ( THREAD_MAIN_TYP  fnc)

◆ start()

SINT32 CAThread::start ( void *  param,
bool  bDaemon = false,
bool  bSilent = false 
)

Starts the execution of the main function of this thread.

The main function could be set with setMainLoop().

Parameters
parama pointer which is used as argument to the main function
bDaemontrue, if this thread should be a deamon thread. A daemon thread is a dettached thread, which will not
bSilentif true, no (log) messages about thats going on are produced. This is especially helpful to avoid any blocking on any mutex during a call to start(). preserve a join state. A daemon thread will automatically release resources which are associated with the thread. Normaly this is done by calling join(). The default value is false.
Return values
E_SUCCESSif the thread could be started successfully
E_UNKNOWNotherwise

References bytes2hex(), E_SUCCESS, E_UNKNOWN, m_fncMainLoop, m_pThread, m_strName, and CAMsg::printMsg().

Referenced by CAAccountingSettleThread::CAAccountingSettleThread(), CAFirstMixChannelList::CAFirstMixChannelList(), CATempIPBlockList::CATempIPBlockList(), CAThreadPool::CAThreadPool(), CALastMix::init(), CAFirstMix::init(), CAFirstMix::initCountryStats(), CALastMixB::loop(), CAMiddleMix::loop(), CACmdLnOptions::reread(), CAInfoService::sendHelo(), CAFirstMixA::shutDown(), CADatabase::start(), CAReplayDatabase::start(), CAInfoService::start(), CAReplayCtrlChannelMsgProc::startTimeStampPorpagation(), and CAQueue::test().

Member Data Documentation

◆ m_fncMainLoop

THREAD_MAIN_TYP CAThread::m_fncMainLoop
private

Referenced by CAThread(), and start().

◆ m_Id

UINT32 CAThread::m_Id
private

Referenced by CAThread().

◆ m_pThread

pthread_t* CAThread::m_pThread
private

Referenced by CAThread(), join(), and start().

◆ m_strName

UINT8* CAThread::m_strName
private

Referenced by CAThread(), join(), and start().

◆ ms_LastId

UINT32 CAThread::ms_LastId =0
staticprivate

Referenced by CAThread().