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

Contents of /innwebd/thread_pool.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.7 - (show annotations)
Fri Apr 11 17:14:49 2008 UTC (17 years, 11 months ago) by sysadm
Branch: MAIN
CVS Tags: HEAD
Changes since 1.6: +2 -6 lines
Content type: text/x-chdr
Update copyright
Add extra log for exception

1 /*******************************************************/
2 /* */
3 /* LeafOK Innbbsd */
4 /* */
5 /* Copyright (C) LeafOK.com, 2003-2008 */
6 /* */
7 /* http://www.leafok.com */
8 /* */
9 /*******************************************************/
10
11 #pragma once
12
13 #include <time.h>
14
15 #define TS_MAX_THREAD 256
16 #define TS_DEFAULT_TIMEOUT 10000
17 #define TS_SETLOCK_TIMEOUT 100
18
19 class thread_pool
20 {
21 public:
22 enum thread_status{
23 S_UNKNOWN = -1,
24 S_UNUSED = 0,
25 S_WORKING = 1,
26 S_WAITING = 2
27 };
28 enum error_code{
29 E_NOERROR = 0,
30 E_LOCK_TIMEOUT = 1,
31 E_MAX_THREAD_EXCEEDED = 2,
32 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:
40 UINT uThreadCount;
41 UINT uThreadMax;
42 ULONG ulThreadIdList[TS_MAX_THREAD];
43 thread_status uThreadStatusList[TS_MAX_THREAD];
44 clock_t time_status_set[TS_MAX_THREAD];
45 clock_t thread_timeout[TS_MAX_THREAD];
46 bool bProcessLock;
47 int SetLock(bool bLock, clock_t tTimeout = TS_SETLOCK_TIMEOUT);
48 error_code uLastErrorCode;
49 ULONG ulThreadKillerId;
50 bool bTerminateThreadKiller;
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(ULONG ulThreadId, clock_t thread_timeout = TS_DEFAULT_TIMEOUT);
57 int RemoveThread(ULONG ulThreadId);
58 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 };

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