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


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

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