Mixe for Privacy and Anonymity in the Internet
Functions
CAThreadPool.cpp File Reference
#include "StdAfx.h"
#include "CAThreadPool.hpp"
#include "CAMsg.hpp"
Include dependency graph for CAThreadPool.cpp:

Go to the source code of this file.

Functions

void * tpool_thread (void *)
 
THREAD_RETURN worker_thread_main_loop (void *arg)
 

Function Documentation

◆ tpool_thread()

void* tpool_thread ( void *  )

◆ worker_thread_main_loop()

THREAD_RETURN worker_thread_main_loop ( void *  arg)

Definition at line 155 of file CAThreadPool.cpp.

156 {
157  CAThreadPool* pPool = (CAThreadPool*)arg;
158  tpool_work_t *my_workp;
159 
160  for(;;)
161  {
162  // Check queue for work
163  pPool->m_pmutexQueue->lock();
164  while ((pPool->m_CurQueueSize == 0) && (!pPool->m_bShutdown))
165  {
166  pPool->m_pcondNotEmpty->wait(pPool->m_pmutexQueue);
167  }
168  //sSleep(5);
169  // Has a shutdown started while i was sleeping?
170  if (pPool->m_bShutdown)
171  {
172  pPool->m_pmutexQueue->unlock();
174  }
175 
176  // Get to work, dequeue the next item
177  my_workp = pPool->m_pQueueHead;
178  pPool->m_CurQueueSize--;
179  if (pPool->m_CurQueueSize == 0)
180  pPool->m_pQueueHead = pPool->m_pQueueTail = NULL;
181  else
182  pPool->m_pQueueHead = my_workp->next;
183 
184  // Handle waiting add_work threads
185  if ((!pPool->m_bDoNotBlockWhenFull) &&
186  (pPool->m_CurQueueSize == (pPool->m_MaxQueueSize - 1)))
187  pPool->m_pcondNotFull->broadcast();
188  // Handle waiting destroyer threads
189  if (pPool->m_CurQueueSize == 0)
190  pPool->m_pcondEmpty->signal();
191  pPool->m_pmutexQueue->unlock();
192 
193  // Do this work item
194  (*(my_workp->routine))(my_workp->arg);
195  delete my_workp;
196  my_workp = NULL;
197  }
198 }
#define THREAD_RETURN_SUCCESS
Definition: StdAfx.h:542
SINT32 signal()
Signals this object.
SINT32 broadcast()
Signals this object.
SINT32 wait()
Waits for a signal or for a timeout.
SINT32 unlock()
Definition: CAMutex.hpp:52
SINT32 lock()
Definition: CAMutex.hpp:41
This class bla bla.
volatile bool m_bShutdown
CAConditionVariable * m_pcondNotFull
CAMutex * m_pmutexQueue
tpool_work_t * m_pQueueTail
CAConditionVariable * m_pcondNotEmpty
volatile UINT32 m_CurQueueSize
bool m_bDoNotBlockWhenFull
UINT32 m_MaxQueueSize
tpool_work_t * m_pQueueHead
CAConditionVariable * m_pcondEmpty
THREAD_MAIN_TYP routine
struct tpool_work * next