|
Mixe for Privacy and Anonymity in the Internet
|
Go to the source code of this file.
Functions | |
| void * | tpool_thread (void *) |
| THREAD_RETURN | worker_thread_main_loop (void *arg) |
| void* tpool_thread | ( | void * | ) |
| THREAD_RETURN worker_thread_main_loop | ( | void * | arg | ) |
Definition at line 155 of file CAThreadPool.cpp.
References tpool_work::arg, CAConditionVariable::broadcast(), CAMutex::lock(), CAThreadPool::m_bDoNotBlockWhenFull, CAThreadPool::m_bShutdown, CAThreadPool::m_CurQueueSize, CAThreadPool::m_MaxQueueSize, CAThreadPool::m_pcondEmpty, CAThreadPool::m_pcondNotEmpty, CAThreadPool::m_pcondNotFull, CAThreadPool::m_pmutexQueue, CAThreadPool::m_pQueueHead, CAThreadPool::m_pQueueTail, tpool_work::next, tpool_work::routine, CAConditionVariable::signal(), THREAD_RETURN_SUCCESS, CAMutex::unlock(), and CAConditionVariable::wait().
{
CAThreadPool* pPool = (CAThreadPool*)arg;
tpool_work_t *my_workp;
for(;;)
{
// Check queue for work
pPool->m_pmutexQueue->lock();
while ((pPool->m_CurQueueSize == 0) && (!pPool->m_bShutdown))
{
pPool->m_pcondNotEmpty->wait(pPool->m_pmutexQueue);
}
//sSleep(5);
// Has a shutdown started while i was sleeping?
if (pPool->m_bShutdown)
{
pPool->m_pmutexQueue->unlock();
THREAD_RETURN_SUCCESS;
}
// Get to work, dequeue the next item
my_workp = pPool->m_pQueueHead;
pPool->m_CurQueueSize--;
if (pPool->m_CurQueueSize == 0)
pPool->m_pQueueHead = pPool->m_pQueueTail = NULL;
else
pPool->m_pQueueHead = my_workp->next;
// Handle waiting add_work threads
if ((!pPool->m_bDoNotBlockWhenFull) &&
(pPool->m_CurQueueSize == (pPool->m_MaxQueueSize - 1)))
pPool->m_pcondNotFull->broadcast();
// Handle waiting destroyer threads
if (pPool->m_CurQueueSize == 0)
pPool->m_pcondEmpty->signal();
pPool->m_pmutexQueue->unlock();
// Do this work item
(*(my_workp->routine))(my_workp->arg);
delete my_workp;
my_workp = NULL;
}
}
1.7.6.1