--- innwebd/thread_pool.h 2004/07/03 08:38:54 1.1 +++ innwebd/thread_pool.h 2008/04/11 17:14:49 1.7 @@ -1,14 +1,10 @@ /*******************************************************/ /* */ -/* LeafOK Innd */ -/* Copyright (C) LeafOK.com, 2003-2004 */ +/* LeafOK Innbbsd */ /* */ -/* Programmed by Leaf */ -/* E-mail:leaf@leafok.com QQ:6049044 */ +/* Copyright (C) LeafOK.com, 2003-2008 */ /* */ -/* http://bbs.leafok.com */ -/* http://bbs.leafok.net */ -/* http://bbs.fenglin.info */ +/* http://www.leafok.com */ /* */ /*******************************************************/ @@ -16,9 +12,9 @@ #include -#define THREAD_SPOOL_MAX_THREAD 256 -#define THREAD_SPOOL_DEFAULT_TIMEOUT 10000 -#define THREAD_SPOOL_SETLOCK_TMEOUT 100 +#define TS_MAX_THREAD 256 +#define TS_DEFAULT_TIMEOUT 10000 +#define TS_SETLOCK_TIMEOUT 100 class thread_pool { @@ -27,31 +23,42 @@ public: S_UNKNOWN = -1, S_UNUSED = 0, S_WORKING = 1, - S_WAITING = 2, - S_TERMINATED = 3 + S_WAITING = 2 }; enum error_code{ E_NOERROR = 0, E_LOCK_TIMEOUT = 1, E_MAX_THREAD_EXCEEDED = 2, - E_THREAD_NOT_FOUND = 3 + E_THREAD_NOT_FOUND = 3, + E_INVALID_TIMEOUT = 4, + E_KILL_THREAD_FAILED = 5, + E_KILLER_BEGIN_FAILED = 6, + E_KILLER_END_FAILED = 7, + E_INVALID_THREAD = 8 }; private: UINT uThreadCount; UINT uThreadMax; - HANDLE hThreadList[THREAD_SPOOL_MAX_THREAD]; - thread_status uThreadStatusList[THREAD_SPOOL_MAX_THREAD]; - double time_status_keep[THREAD_SPOOL_MAX_THREAD]; - double thread_timeout; + ULONG ulThreadIdList[TS_MAX_THREAD]; + thread_status uThreadStatusList[TS_MAX_THREAD]; + clock_t time_status_set[TS_MAX_THREAD]; + clock_t thread_timeout[TS_MAX_THREAD]; bool bProcessLock; - int SetLock(bool bLock, time_t tTimeout = THREAD_SPOOL_SETLOCK_TMEOUT); + int SetLock(bool bLock, clock_t tTimeout = TS_SETLOCK_TIMEOUT); error_code uLastErrorCode; + ULONG ulThreadKillerId; + bool bTerminateThreadKiller; public: - thread_pool(UINT uThreadMax = THREAD_SPOOL_MAX_THREAD, double thread_timeout = THREAD_SPOOL_DEFAULT_TIMEOUT); + thread_pool(UINT uThreadMax = TS_MAX_THREAD); ~thread_pool(void); - UINT GetLastError(void); - int AddThread(HANDLE hThread); - int RemoveThread(HANDLE hThread); - int SetThreadStatus(HANDLE hThread, UINT uStatus); - UINT GetThreadStatus(HANDLE hThread); + static DWORD KillDeadThread(LPVOID pParam); + int GetLastError(void) const; + int AddThread(ULONG ulThreadId, clock_t thread_timeout = TS_DEFAULT_TIMEOUT); + int RemoveThread(ULONG ulThreadId); + int SetThreadStatus(ULONG ulThreadId, int uStatus); + int GetThreadStatus(ULONG ulThreadId); + int GetThreadCount(void) const; + int EnableKillDeadThread(void); + int DisableKillDeadThread(void); + int KillAllThread(void); };