- Main Page
- Related Pages
- Namespaces
- Classes
- Files

- File List

# src/TaskBasedFlockSim/ThreadPool.h

    00001
    00002
    00003
    00004
    00005
    00006
    00007
    00008
    00009
    00010
    00011
    00012
    00013
    00014
    00015
    00016
    00017
    00018
    00019
    00020 #ifndef _THREAD_POOL_H_
    00021 #define _THREAD_POOL_H_
    00022
    00023 #include <windows.h>
    00024
    00025 #include <boost\utility.hpp>
    00026 #include <vector>
    00027
    00028 namespace TaskBasedFlockSim
    00029 {
    00030
    00031 class TaskContext;
    00032 class ITask;
    00033
    00034 class ThreadPool :
    00035         boost::noncopyable
    00036 {
    00037 public:
    00038         ThreadPool(void);
    00039
    00040         ThreadPool(size_t minThreadsCount, size_t maxThreadsCount);
    00041
    00042         ~ThreadPool(void);
    00043
    00044         void SubmitTasks(TaskContext* context);
    00045
    00046 private:
    00047         struct TaskCallbackContext
    00048         {
    00049                 ThreadPool* m_threadPool;
    00050                 ITask* m_task;
    00051                 TaskContext* m_context;
    00052
    00053                 TaskCallbackContext(ThreadPool* threadPool,
    00054                                                         ITask* task,
    00055                                                         TaskContext* context)   :       m_threadPool(threadPool),
    00056                                                                                                                 m_task(task),
    00057                                                                                                                 m_context(context)
    00058                 {
    00059                 }
    00060
    00061                 TaskCallbackContext(const TaskCallbackContext& taskCallbackContext)     :       m_threadPool(taskCallbackContext.m_threadPool),
    00062                                                                                                                                                                 m_task(taskCallbackContext.m_task),
    00063                                                                                                                                                                 m_context(taskCallbackContext.m_context)
    00064                 {
    00065                 }
    00066
    00067                 TaskCallbackContext& operator=(const TaskCallbackContext& taskCallbackContext)
    00068                 {
    00069                         m_threadPool = taskCallbackContext.m_threadPool;
    00070                         m_task = taskCallbackContext.m_task;
    00071                         m_context = taskCallbackContext.m_context;
    00072
    00073                         return *this;
    00074                 }
    00075         };
    00076
    00077         PTP_POOL m_pool;
    00078
    00079         std::vector<TaskCallbackContext> m_taskCallbacksContext;
    00080
    00081         void SetDefaultThreadsCount(void);
    00082
    00083         void SetThreadsCount(size_t minThreadsCount, size_t maxThreadsCount);
    00084
    00085         friend VOID CALLBACK TaskCallback(PTP_CALLBACK_INSTANCE instance, PVOID context);
    00086 };
    00087
    00088 }
    00089
    00090 #endif