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

Contents of /innwebd/thread_pool.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.3 - (show annotations)
Sat Jul 3 13:55:42 2004 UTC (21 years, 8 months ago) by sysadm
Branch: MAIN
Changes since 1.2: +9 -6 lines
Content type: text/x-chdr
no message

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

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