/[LeafOK_CVS]/innwebd/thread_pool.h
ViewVC logotype

Diff of /innwebd/thread_pool.h

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 1.1 by sysadm, Sat Jul 3 08:38:54 2004 UTC Revision 1.7 by sysadm, Fri Apr 11 17:14:49 2008 UTC
# Line 1  Line 1 
1  /*******************************************************/  /*******************************************************/
2  /*                                                     */  /*                                                     */
3  /*  LeafOK Innd                                        */  /*  LeafOK Innbbsd                                     */
 /*  Copyright (C) LeafOK.com, 2003-2004                */  
4  /*                                                     */  /*                                                     */
5  /*  Programmed by Leaf                                 */  /*  Copyright (C) LeafOK.com, 2003-2008                */
 /*  E-mail:leaf@leafok.com  QQ:6049044                 */  
6  /*                                                     */  /*                                                     */
7  /*  http://bbs.leafok.com                              */  /*  http://www.leafok.com                              */
 /*  http://bbs.leafok.net                              */  
 /*  http://bbs.fenglin.info                            */  
8  /*                                                     */  /*                                                     */
9  /*******************************************************/  /*******************************************************/
10    
# Line 16  Line 12 
12    
13  #include <time.h>  #include <time.h>
14    
15  #define THREAD_SPOOL_MAX_THREAD 256  #define TS_MAX_THREAD                   256
16  #define THREAD_SPOOL_DEFAULT_TIMEOUT 10000  #define TS_DEFAULT_TIMEOUT              10000
17  #define THREAD_SPOOL_SETLOCK_TMEOUT 100  #define TS_SETLOCK_TIMEOUT              100
18    
19  class thread_pool  class thread_pool
20  {  {
# Line 27  public: Line 23  public:
23                  S_UNKNOWN                               =       -1,                  S_UNKNOWN                               =       -1,
24                  S_UNUSED                                =       0,                  S_UNUSED                                =       0,
25                  S_WORKING                               =       1,                  S_WORKING                               =       1,
26                  S_WAITING                               =       2,                  S_WAITING                               =       2
                 S_TERMINATED                    =       3  
27          };          };
28          enum error_code{          enum error_code{
29                  E_NOERROR                               =       0,                  E_NOERROR                               =       0,
30                  E_LOCK_TIMEOUT                  =       1,                  E_LOCK_TIMEOUT                  =       1,
31                  E_MAX_THREAD_EXCEEDED   =       2,                  E_MAX_THREAD_EXCEEDED   =       2,
32                  E_THREAD_NOT_FOUND              =       3                  E_THREAD_NOT_FOUND              =       3,
33                    E_INVALID_TIMEOUT               =       4,
34                    E_KILL_THREAD_FAILED    =       5,
35                    E_KILLER_BEGIN_FAILED   =       6,
36                    E_KILLER_END_FAILED             =       7,
37                    E_INVALID_THREAD                =       8
38          };          };
39  private:  private:
40          UINT uThreadCount;          UINT uThreadCount;
41          UINT uThreadMax;          UINT uThreadMax;
42          HANDLE hThreadList[THREAD_SPOOL_MAX_THREAD];          ULONG ulThreadIdList[TS_MAX_THREAD];
43          thread_status uThreadStatusList[THREAD_SPOOL_MAX_THREAD];          thread_status uThreadStatusList[TS_MAX_THREAD];
44          double time_status_keep[THREAD_SPOOL_MAX_THREAD];          clock_t time_status_set[TS_MAX_THREAD];
45          double thread_timeout;          clock_t thread_timeout[TS_MAX_THREAD];
46          bool bProcessLock;          bool bProcessLock;
47          int SetLock(bool bLock, time_t tTimeout = THREAD_SPOOL_SETLOCK_TMEOUT);          int SetLock(bool bLock, clock_t tTimeout = TS_SETLOCK_TIMEOUT);
48          error_code uLastErrorCode;          error_code uLastErrorCode;
49            ULONG ulThreadKillerId;
50            bool bTerminateThreadKiller;
51  public:  public:
52          thread_pool(UINT uThreadMax = THREAD_SPOOL_MAX_THREAD, double thread_timeout = THREAD_SPOOL_DEFAULT_TIMEOUT);          thread_pool(UINT uThreadMax = TS_MAX_THREAD);
53          ~thread_pool(void);          ~thread_pool(void);
54          UINT GetLastError(void);          static DWORD KillDeadThread(LPVOID pParam);
55          int AddThread(HANDLE hThread);          int GetLastError(void) const;
56          int RemoveThread(HANDLE hThread);          int AddThread(ULONG ulThreadId, clock_t thread_timeout = TS_DEFAULT_TIMEOUT);
57          int SetThreadStatus(HANDLE hThread, UINT uStatus);          int RemoveThread(ULONG ulThreadId);
58          UINT GetThreadStatus(HANDLE hThread);          int SetThreadStatus(ULONG ulThreadId, int uStatus);
59            int GetThreadStatus(ULONG ulThreadId);
60            int GetThreadCount(void) const;
61            int EnableKillDeadThread(void);
62            int DisableKillDeadThread(void);
63            int KillAllThread(void);
64  };  };


Legend:
Removed lines/characters  
Changed lines/characters
  Added lines/characters

webmaster@leafok.com
ViewVC Help
Powered by ViewVC 1.3.0-beta1