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

typedef struct tpool_work tpool_work_t

Definition at line 24 of file CAThreadPool.hpp.


Function Documentation

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;
  } 
}

Here is the call graph for this function: