Statistics
| Revision:

svn-gvsig-desktop / tags / extI18n-0.1.0-1045_8 / libraries / libjni-ecwcompress / include / NCSThread.h @ 43745

History | View | Annotate | Download (4.18 KB)

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