Mixe for Privacy and Anonymity in the Internet
Classes | Typedefs | Functions
CAThreadPool.hpp File Reference
#include "CAMutex.hpp"
#include "CAThread.hpp"
#include "CAConditionVariable.hpp"
Include dependency graph for CAThreadPool.hpp:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  tpool_work
 
class  CAThreadPool
 This class bla bla. More...
 

Typedefs

typedef struct tpool_work tpool_work_t
 

Functions

THREAD_RETURN worker_thread_main_loop (void *args)
 

Typedef Documentation

◆ tpool_work_t

typedef struct tpool_work tpool_work_t

Definition at line 1 of file CAThreadPool.hpp.

Function Documentation

◆ worker_thread_main_loop()

THREAD_RETURN worker_thread_main_loop ( void *  args)

Definition at line 50 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