📄 warthreadpool.h
字号:
/** */#ifndef WAR_THREAD_POOL_H#define WAR_THREAD_POOL_H/* SYSTEM INCLUDES */#ifndef WAR_LIST_INCLUDED# define WAR_LIST_INCLUDED# include <list>#endif/* PROJECT INCLUDES */#ifndef WAR_TYPES_H# include "WarTypes.h"#endif#ifndef WAR_PTR_WRAPPER_H# include "WarPtrWrapper.h"#endif#ifndef WAR_EXCEPTION_H# include "WarException.h"#endif#ifndef WAR_CRITICAL_SECTION_H# include "WarCriticalSection.h"#endif#ifndef WAR_THREAD_EVENT_H# include "WarThreadEvent.h"#endif/* LOCAL INCLUDES *//* FORWARD REFERENCES */class WarThreadForPool;class WarThreadPoolTask;#ifdef __cplusplusextern "C" {#endif/****************** BEGIN OLD STYLE C spesific ********//****************** END OLD STYLE C spesific **********/#ifdef __cplusplus }#endif/****************** BEGIN C++ spesific ****************/#ifdef __cplusplusclass WarThreadPool {public: /// typedef std::list < WarPtrWrapper<WarThreadForPool> >thread_list_t; /// typedef std::list < WarPtrWrapper<WarThreadPoolTask> >task_queue_t; // LIFECYCLE /// WarThreadPool(); /// virtual ~WarThreadPool(); // OPERATORS // OPERATIONS // virtual void Create(war_uint32_t MinThreads, war_uint32_t MaxThreads) throw(WarException); /// Add a task to the work queue void PushTask(WarThreadPoolTask * pTask) throw(WarException); /** Get a task from the done-queue. */ WarPtrWrapper<WarThreadPoolTask> PopDoneTask(); /// void FlagAllThreads(bool doAbort, bool doExit); /// bool AbortTask(WarThreadPoolTask * pTask); /// Remove all tasks from the queues and abort any current operations void KillAllTasks(); /// void RemoveFromDoneQueue(WarThreadPoolTask * pTask); /// void TerminateAllThreads(bool doAbort = false); // ACCESS // INQUIRY /// size_t GetNumThreads(); /// int GetNumIdleThreads(); /// For debugging std::string ListCurrentTasks(war_ccstr_t Label); protected: friend class WarThreadForPool; void Attach(WarThreadForPool *pThread); void Detach(WarThreadForPool *pThread); WarThreadPoolTask *PopTask(); /// Called when a request is due void WarThreadPool::TaskDone( WarPtrWrapper<WarThreadPoolTask>& rWrapedTask, bool isAborted); /// Overload to create the right object! virtual WarThreadForPool *NewThread(); /// Use to create a new thread object and start the thread void StartNewThread() throw(WarException); std::string ListCurrentTasks(const task_queue_t & List, war_ccstr_t Label) const; /// std::string ListCurrentThreads() ; /// war_uint32_t mMaxThreads; /// war_uint32_t mMinThreads; /// WarCriticalSection mLock; /// WarThreadEvent mSignal; /// thread_list_t mThreads; /// Tasks to process task_queue_t mPendingQueue; /// Task currentky being processed task_queue_t mProcessingQueue; /// Tasks that are processed, but not poped by the caller yet task_queue_t mDoneQueue;private: // Lock before use. Returns true if the task exist in the queue. bool CheckIfExist(task_queue_t & List, WarThreadPoolTask * pTask, bool doRemove = false); int mCntThreadsExist; // Total threads that exist, from creation to destruuction};/* INLINE METHODS *//* EXTERNAL REFERENCES */#endif /* __cplusplus *//****************** END C++ spesific ******************/#endif /* WAR_THREAD_POOL_H_ */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -