|
Mixe for Privacy and Anonymity in the Internet
|
This class could be used for creating a new thread. More...
#include <CAThread.hpp>
Public Member Functions | |
| CAThread () | |
| Creates a CAThread object but no actual thread. | |
| CAThread (const UINT8 *strName) | |
| Creates a CAThread object but no actual thread. | |
| ~CAThread () | |
| SINT32 | setMainLoop (THREAD_MAIN_TYP fnc) |
| Sets the main function which will be executed within this thread. | |
| SINT32 | start (void *param, bool bDaemon=false, bool bSilent=false) |
| Starts the execution of the main function of this thread. | |
| SINT32 | join () |
| Waits for the main function to finish execution. | |
| UINT8 * | getName () const |
| UINT32 | getID () const |
Static Public Member Functions | |
| static thread_id_t | getSelfID () |
Private Attributes | |
| THREAD_MAIN_TYP | m_fncMainLoop |
| pthread_t * | m_pThread |
| UINT8 * | m_strName |
| UINT32 | m_Id |
Static Private Attributes | |
| static UINT32 | ms_LastId = 0 |
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) { THREAD_RETURN_SUCCESS }
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 at line 104 of file CAThread.hpp.
Creates a CAThread object but no actual thread.
Definition at line 54 of file CAThread.cpp.
References m_fncMainLoop, m_Id, m_pThread, m_strName, and ms_LastId.
| CAThread::CAThread | ( | const UINT8 * | strName | ) |
Creates a CAThread object but no actual thread.
| strName | a name for this thread, useful mostly for debugging |
Definition at line 70 of file CAThread.cpp.
References len, m_fncMainLoop, m_Id, m_pThread, m_strName, and ms_LastId.
| CAThread::~CAThread | ( | ) | [inline] |
| UINT32 CAThread::getID | ( | ) | const [inline] |
| UINT8* CAThread::getName | ( | ) | const [inline] |
| static thread_id_t CAThread::getSelfID | ( | ) | [inline, static] |
Definition at line 198 of file CAThread.hpp.
Referenced by CAAccountingDBInterface::checkOwner(), openssl_get_thread_id(), CAAccountingDBInterface::testAndResetOwner(), and CAAccountingDBInterface::testAndSetOwner().
{
#ifdef _WIN32
return (unsigned long) pthread_self().p;
#else
return (unsigned long) pthread_self();
#endif
}
| SINT32 CAThread::join | ( | ) |
Waits for the main function to finish execution.
A call of this method will block until the main function exits.
| E_SUCCESS | if successful |
| E_UNKNOWN | otherwise |
Definition at line 190 of file CAThread.cpp.
References E_SUCCESS, E_UNKNOWN, m_pThread, m_strName, and CAMsg::printMsg().
Referenced by CALastMix::clean(), CAFirstMix::clean(), CAFirstMix::deleteCountryStats(), CAThreadPool::destroy(), CALastMixA::loop(), CAFirstMixB::loop(), CAFirstMixA::loop(), CALastMixB::loop(), CAMiddleMix::loop(), CAFirstMixA::shutDown(), CADatabase::stop(), CAReplayDatabase::stop(), CAInfoService::stop(), CAReplayCtrlChannelMsgProc::stopTimeStampPorpagation(), CAQueue::test(), CAAccountingSettleThread::~CAAccountingSettleThread(), CAFirstMixChannelList::~CAFirstMixChannelList(), and CATempIPBlockList::~CATempIPBlockList().
{
#ifdef OS_TUDOS
CAMsg::printMsg(LOG_ERR,"CAThread - join() L4 implement me !\n");
if(m_Thread==L4THREAD_INVALID_ID)
return E_SUCCESS;
return E_UNKNOWN;
#else
if(m_pThread==NULL)
return E_SUCCESS;
SINT32 ret=pthread_join(*m_pThread,NULL);
if(ret==0)
{
#ifdef DEBUG
CAMsg::printMsg(LOG_DEBUG,"CAThread %s - join() successful\n", m_strName);
m_pThreadList->remove(this);
#endif
delete m_pThread;
m_pThread=NULL;
return E_SUCCESS;
}
else
{
CAMsg::printMsg(LOG_ERR,"CAThread - join() not successful - Error was: %i\n",ret);
return E_UNKNOWN;
}
#endif
}
| SINT32 CAThread::setMainLoop | ( | THREAD_MAIN_TYP | fnc | ) | [inline] |
Sets the main function which will be executed within this thread.
| fnc | the fuction to be executed |
| E_SUCCESS |
Definition at line 145 of file CAThread.hpp.
References E_SUCCESS, and m_fncMainLoop.
Referenced by CAAccountingSettleThread::CAAccountingSettleThread(), CAFirstMixChannelList::CAFirstMixChannelList(), CATempIPBlockList::CATempIPBlockList(), CAThreadPool::CAThreadPool(), CALastMix::init(), CAFirstMix::init(), CAFirstMix::initCountryStats(), CALastMixA::loop(), CAFirstMixA::loop(), CALastMixB::loop(), CAMiddleMix::loop(), CACmdLnOptions::reread(), CAInfoService::sendHelo(), CADatabase::start(), CAReplayDatabase::start(), CAInfoService::start(), CAReplayCtrlChannelMsgProc::startTimeStampPorpagation(), and CAQueue::test().
{
m_fncMainLoop=fnc;
return E_SUCCESS;
}
| 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().
| param | a pointer which is used as argument to the main function |
| bDaemon | true, if this thread should be a deamon thread. A daemon thread is a dettached thread, which will not |
| bSilent | if 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. |
| E_SUCCESS | if the thread could be started successfully |
| E_UNKNOWN | otherwise |
Definition at line 118 of file CAThread.cpp.
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(), CALastMixA::loop(), CAFirstMixA::loop(), CALastMixB::loop(), CAMiddleMix::loop(), CACmdLnOptions::reread(), CAInfoService::sendHelo(), CADatabase::start(), CAReplayDatabase::start(), CAInfoService::start(), CAReplayCtrlChannelMsgProc::startTimeStampPorpagation(), and CAQueue::test().
{
if(m_fncMainLoop==NULL)
return E_UNKNOWN;
#ifndef OS_TUDOS
m_pThread=new pthread_t;
#endif
#ifdef DEBUG
if(!bSilent)
CAMsg::printMsg(LOG_DEBUG, "CAThread::start() - creating thread\n");
#endif
#ifdef OS_TUDOS
if ((m_Thread = l4thread_create(m_fncMainLoop, param, L4THREAD_CREATE_ASYNC)) < 1)
{
m_Thread = L4THREAD_INVALID_ID;
if(!bSilent)
CAMsg::printMsg(LOG_ERR, "CAThread::start() - creating new thread failed!\n");
return E_UNKNOWN;
}
#else
SINT32 ret=pthread_create(m_pThread,NULL,m_fncMainLoop,param);
if(ret!=0)
{
if(!bSilent)
CAMsg::printMsg(LOG_ERR, "CAThread::start() - creating new thread failed! - Err: %i\n",ret);
delete m_pThread;
m_pThread=NULL;
return E_UNKNOWN;
}
#endif
#ifdef _DEBUG
if(m_pThreadList != NULL)
{
m_pThreadList->put(this);
}
else
{
CAMsg::printMsg(LOG_DEBUG, "CAThread::start() - Warning no thread list found\n");
}
#endif
#ifdef DEBUG
if(!bSilent)
CAMsg::printMsg(LOG_DEBUG, "CAThread::start() - thread created sucessful\n");
#endif
#ifdef OS_TUDOS
if(m_strName!=NULL&&!bSilent)
CAMsg::printMsg(LOG_DEBUG,
"Thread with name: %s created - pthread_t: "l4util_idfmt"\n",
m_strName, l4util_idstr(l4thread_l4_id(m_Thread)));
if(bDaemon)
CAMsg::printMsg(LOG_ERR, "TODO: Emulate pthread_detach on L4 ?!\n");
#else
if(m_strName!=NULL&&!bSilent)
{
UINT8* temp=bytes2hex(m_pThread,sizeof(pthread_t));
CAMsg::printMsg(LOG_DEBUG,"Thread with name: %s created - pthread_t: %s\n",m_strName,temp);
delete[] temp;
temp = NULL;
}
if(bDaemon)
pthread_detach(*m_pThread);
#endif
return E_SUCCESS;
}
THREAD_MAIN_TYP CAThread::m_fncMainLoop [private] |
Definition at line 220 of file CAThread.hpp.
Referenced by CAThread(), setMainLoop(), and start().
UINT32 CAThread::m_Id [private] |
Definition at line 227 of file CAThread.hpp.
Referenced by CAThread(), and getID().
pthread_t* CAThread::m_pThread [private] |
Definition at line 224 of file CAThread.hpp.
Referenced by CAThread(), join(), start(), and ~CAThread().
UINT8* CAThread::m_strName [private] |
Definition at line 226 of file CAThread.hpp.
Referenced by CAThread(), getName(), join(), start(), and ~CAThread().
UINT32 CAThread::ms_LastId = 0 [static, private] |
Definition at line 228 of file CAThread.hpp.
Referenced by CAThread().
1.7.6.1