svn-gvsig-desktop / tags / v1_0_2_Build_907 / libraries / libjni-ecw / include / NCSThread.h @ 44116
History | View | Annotate | Download (4.45 KB)
1 | 3538 | nacho | /********************************************************
|
---|---|---|---|
2 | ** Copyright 1999 Earth Resource Mapping Ltd.
|
||
3 | ** This document contains proprietary source code of
|
||
4 | ** Earth Resource Mapping Ltd, and can only be used under
|
||
5 | ** one of the three licenses as described in the
|
||
6 | ** license.txt file supplied with this distribution.
|
||
7 | ** See separate license.txt file for license details
|
||
8 | ** and conditions.
|
||
9 | **
|
||
10 | ** This software is covered by US patent #6,442,298,
|
||
11 | ** #6,102,897 and #6,633,688. Rights to use these patents
|
||
12 | ** is included in the license agreements.
|
||
13 | **
|
||
14 | ** FILE: NCSThread.h
|
||
15 | ** CREATED: Fri Feb 26 09:19:00 WST 1999
|
||
16 | ** AUTHOR: Simon Cope
|
||
17 | ** PURPOSE: NCS Thread handling.
|
||
18 | ** EDITS:
|
||
19 | ** [01] 03Jan01 ny Added CNCSThread wrapper class
|
||
20 | ** [02] 02May01 ny Added GetSysID() method
|
||
21 | *******************************************************/
|
||
22 | |||
23 | #ifndef NCSTHREAD_H
|
||
24 | #define NCSTHREAD_H
|
||
25 | |||
26 | #ifndef NCSTTYPES_H
|
||
27 | #include "NCSTypes.h" |
||
28 | #endif
|
||
29 | |||
30 | #ifdef WIN32
|
||
31 | #ifndef _WIN32_WCE
|
||
32 | #include <process.h> |
||
33 | #endif /* _WIN32_WCE */ |
||
34 | #include <windows.h> |
||
35 | #ifdef _WIN32_WINNT
|
||
36 | #include <winbase.h> |
||
37 | #endif
|
||
38 | |||
39 | #elif defined MACINTOSH
|
||
40 | # ifdef MAC_PREEMPTIVE
|
||
41 | # include <Multiprocessing.h> |
||
42 | # else
|
||
43 | # include <Threads.h> |
||
44 | # endif //MAC_PREEMPTIVE |
||
45 | #elif defined POSIX
|
||
46 | #include <pthread.h> |
||
47 | #endif
|
||
48 | |||
49 | #ifdef __cplusplus
|
||
50 | extern "C" { |
||
51 | #endif
|
||
52 | |||
53 | #ifndef NCSTIMESTAMP_H
|
||
54 | #include "NCSTimeStamp.h" |
||
55 | #endif
|
||
56 | #ifndef NCSMALLOC_H
|
||
57 | #include "NCSMalloc.h" |
||
58 | #endif
|
||
59 | #ifndef NCSMUTEX_H
|
||
60 | #include "NCSMutex.h" |
||
61 | #endif
|
||
62 | |||
63 | typedef struct { |
||
64 | NCSTimeStampMs tsStart; |
||
65 | NCSTimeStampMs tsTotalRunning; |
||
66 | NCSTimeStampMs tsSuspendStart; |
||
67 | NCSTimeStampMs tsTotalSuspended; |
||
68 | INT64 nSuspends; |
||
69 | INT64 nResumes; |
||
70 | } NCSThreadStats; |
||
71 | |||
72 | typedef enum { |
||
73 | NCS_THREAD_PRI_IDLE = 0,
|
||
74 | NCS_THREAD_PRI_BELOW_NORMAL = 1,
|
||
75 | NCS_THREAD_PRI_NORMAL = 2,
|
||
76 | NCS_THREAD_PRI_ABOVE_NORMAL = 3,
|
||
77 | NCS_THREAD_PRI_REALTIME = 4
|
||
78 | } NCSThreadPriority; |
||
79 | |||
80 | typedef UINT32 NCSThread;
|
||
81 | #define NCS_NULL_THREAD_ID 0 |
||
82 | |||
83 | #if defined(WIN32)||defined(MACINTOSH)
|
||
84 | typedef UINT32 NCSThreadLSKey;
|
||
85 | #elif defined(POSIX)
|
||
86 | typedef pthread_key_t *NCSThreadLSKey;
|
||
87 | #endif
|
||
88 | |||
89 | void NCSThreadInit(void); |
||
90 | void NCSThreadFini(void); |
||
91 | BOOLEAN NCSThreadSpawn(NCSThread *pThread, void (*pFunc)(void*), void *pData, BOOLEAN bCreateSuspended); |
||
92 | void NCSThreadFreeInfo(NCSThread *pThread);
|
||
93 | void NCSThreadExit(INT32 dwExitId);
|
||
94 | void NCSThreadSuspend(void); |
||
95 | void NCSThreadResume(NCSThread *pThread);
|
||
96 | NCSThread *NCSThreadGetCurrent(void);
|
||
97 | NCSThreadStats NCSThreadGetStats(NCSThread *pThread); |
||
98 | void NCSThreadEnableStats(NCSThread *pThread);
|
||
99 | void NCSThreadDisableStats(NCSThread *pThread);
|
||
100 | BOOLEAN NCSThreadIsRunning(NCSThread *pThread); |
||
101 | BOOLEAN NCSThreadIsSuspended(NCSThread *pThread); |
||
102 | BOOLEAN NCSThreadYield(void);
|
||
103 | BOOLEAN NCSThreadSetPriority(NCSThread *pThread, NCSThreadPriority pri); |
||
104 | NCSThreadPriority NCSThreadGetPriority(NCSThread *pThread); |
||
105 | |||
106 | NCSThreadLSKey NCSThreadLSAlloc(void);
|
||
107 | void NCSThreadLSFree(NCSThreadLSKey Key);
|
||
108 | void NCSThreadLSSetValue(NCSThreadLSKey Key, void *pValue); |
||
109 | void *NCSThreadLSGetValue(NCSThreadLSKey Key);
|
||
110 | |||
111 | BOOLEAN NCSThreadTerminate(NCSThread *pThread); |
||
112 | #ifdef WIN32
|
||
113 | DWORD NCSThreadGetSysID(NCSThread* t); |
||
114 | #elif defined(MACINTOSH)
|
||
115 | # ifdef MAC_PREEMPTIVE
|
||
116 | # define MacThreadID MPTaskID
|
||
117 | # else
|
||
118 | # define MacThreadID ThreadID
|
||
119 | # endif //MAC_PREEMPTIVE |
||
120 | MacThreadID NCSThreadGetSysID(NCSThread* t); |
||
121 | #elif defined(POSIX)
|
||
122 | pthread_t *NCSThreadGetSysID(NCSThread* t); |
||
123 | #else
|
||
124 | ERROR: Need NCSThreadGetSysID() prototype in NCSThread.h
|
||
125 | #endif //[07] |
||
126 | |||
127 | #ifdef __cplusplus
|
||
128 | } |
||
129 | |||
130 | #ifndef NCS_NO_UTIL_LINK
|
||
131 | |||
132 | // CNCSThread
|
||
133 | class NCS_EXPORT CNCSThread { |
||
134 | private:
|
||
135 | NCSThread m_Thread; |
||
136 | bool m_bRun;
|
||
137 | static void ThreadFunc(void *pDataParam); |
||
138 | void FreeInfo();
|
||
139 | |||
140 | public:
|
||
141 | void *m_pData;
|
||
142 | |||
143 | CNCSThread(); |
||
144 | virtual ~CNCSThread(); |
||
145 | virtual bool Spawn(void *pData, bool bCreateSuspended); |
||
146 | |||
147 | virtual void Exit(INT32 dwExitId);
|
||
148 | virtual void Suspend(void); |
||
149 | virtual void Resume();
|
||
150 | virtual NCSThread *GetCurrent(void);
|
||
151 | virtual NCSThreadStats GetStats(); |
||
152 | virtual void EnableStats();
|
||
153 | virtual void DisableStats();
|
||
154 | virtual bool IsRunning();
|
||
155 | virtual bool IsSuspended();
|
||
156 | virtual bool ThreadYield(void); |
||
157 | virtual bool SetPriority(NCSThreadPriority pri);
|
||
158 | virtual NCSThreadPriority GetPriority(); |
||
159 | virtual bool Terminate();
|
||
160 | virtual bool Run();
|
||
161 | virtual bool Stop(bool bWait = true); |
||
162 | |||
163 | virtual void Work(void *pData) = 0; |
||
164 | |||
165 | virtual NCSThread GetID(void);
|
||
166 | |||
167 | #ifdef WIN32
|
||
168 | virtual DWORD GetSysID(void);
|
||
169 | #elif defined MACINTOSH
|
||
170 | virtual MacThreadID GetSysID(void);
|
||
171 | #elif defined POSIX
|
||
172 | virtual pthread_t *GetSysID(void);
|
||
173 | #endif
|
||
174 | }; |
||
175 | |||
176 | #endif //NCS_NO_UTIL_LINK |
||
177 | |||
178 | #endif // __cplusplus |
||
179 | |||
180 | #endif /* NCSTHREAD_H */ |