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

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

@ingroup threading

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)
{
}
#define THREAD_RETURN
Definition: StdAfx.h:540
#define THREAD_RETURN_SUCCESS
Definition: StdAfx.h:542

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;
Definition: CAThread.hpp:115
CAThread()
Creates a CAThread object but no actual thread.
Definition: CAThread.cpp:54
SINT32 start(void *param, bool bDaemon=false, bool bSilent=false)
Starts the execution of the main function of this thread.
Definition: CAThread.cpp:115
SINT32 setMainLoop(THREAD_MAIN_TYP fnc)
Sets the main function which will be executed within this thread.
Definition: CAThread.hpp:148
SINT32 join()
Waits for the main function to finish execution.
Definition: CAThread.cpp:187

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 ( )

References m_pThread, and m_strName.

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 CACryptoBenchmark::benchmarkThread(), CAAccountingSettleThread::CAAccountingSettleThread(), CAFirstMixChannelList::CAFirstMixChannelList(), CATempIPBlockList::CATempIPBlockList(), CAThreadPool::CAThreadPool(), CACryptoBenchmark::doBenchmark(), CAFirstMix::init(), CAFirstMix::initCountryStats(), CAMiddleMix::loop(), CAFirstMixA::loop(), CALastMixA::loop(), CALastMixB::loop(), CACmdLnOptions::reread(), CAInfoService::sendHelo(), CADatabase::start(), CAInfoService::start(), CAReplayDatabase::start(), CAReplayCtrlChannelMsgProc::startTimeStampPorpagation(), and CAQueue::test().

Member Data Documentation

◆ m_fncMainLoop

THREAD_MAIN_TYP CAThread::m_fncMainLoop
private

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

◆ m_Id

UINT32 CAThread::m_Id
private

Referenced by CAThread(), and getID().

◆ m_pThread

pthread_t* CAThread::m_pThread
private

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

◆ m_strName

UINT8* CAThread::m_strName
private

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

◆ ms_LastId

UINT32 CAThread::ms_LastId =0
staticprivate

Referenced by CAThread().