Mixe for Privacy and Anonymity in the Internet
CAThreadPool.hpp
Go to the documentation of this file.
1 /********************************************************
2  * A thread pool class inspired by:
3  * "Using POSIX Threads: Programming with Pthreads"
4  * by Brad nichols, Dick Buttlar, Jackie Farrell
5  * O'Reilly & Associates, Inc.
6  *
7  ********************************************************/
8 
9 #ifndef __CATHREADPOOL__
10 #define __CATHREADPOOL__
11 
12 #include "CAMutex.hpp"
13 #if !defined ONLY_LOCAL_PROXY || defined INCLUDE_FIRST_MIX
14 #include "CAThread.hpp"
15 #include "CAConditionVariable.hpp"
16 
17 struct tpool_work
18  {
20  void *arg;
21  struct tpool_work *next;
22  };
23 
24 typedef struct tpool_work tpool_work_t;
25 
27 
32  {
33  public:
34  CAThreadPool( UINT32 num_worker_threads,
35  UINT32 max_queue_size,
36  bool b_do_not_block_when_full);
38  {
39  destroy(true);
40  }
44  SINT32 destroy(bool bWaitForFinish);
45  SINT32 addRequest(THREAD_MAIN_TYP, void *args);
47  {
48  return m_CurQueueSize;
49  }
50  friend THREAD_RETURN worker_thread_main_loop(void *args);
51  private:
52  /* pool characteristics */
56  /* pool state */
61  volatile bool m_bQueueClosed;
62  volatile bool m_bShutdown;
63  /* pool synchronization */
68  };
69 #endif //ONLY_LOCAL_PROXY
70 
71 #endif
THREAD_RETURN(* THREAD_MAIN_TYP)(void *)
Defines the type of the main function of the thread.
Definition: CAThread.hpp:67
THREAD_RETURN worker_thread_main_loop(void *args)
#define THREAD_RETURN
Definition: StdAfx.h:540
signed int SINT32
Definition: basetypedefs.h:132
unsigned int UINT32
Definition: basetypedefs.h:131
This class bla bla.
CAThread ** m_parThreads
volatile bool m_bShutdown
CAConditionVariable * m_pcondNotFull
CAMutex * m_pmutexQueue
friend THREAD_RETURN worker_thread_main_loop(void *args)
SINT32 destroy(bool bWaitForFinish)
tpool_work_t * m_pQueueTail
SINT32 addRequest(THREAD_MAIN_TYP, void *args)
Adds a new request (task) to this threadpool.
volatile bool m_bQueueClosed
UINT32 m_NumThreads
CAConditionVariable * m_pcondNotEmpty
volatile UINT32 m_CurQueueSize
UINT32 countRequests()
CAThreadPool(UINT32 num_worker_threads, UINT32 max_queue_size, bool b_do_not_block_when_full)
bool m_bDoNotBlockWhenFull
UINT32 m_MaxQueueSize
tpool_work_t * m_pQueueHead
CAConditionVariable * m_pcondEmpty
THREAD_MAIN_TYP routine
struct tpool_work * next