svn-gvsig-desktop / branches / v05 / libraries / libjni-ecw / include / NCSMutex.h @ 34016
History | View | Annotate | Download (3.84 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: NCSMutex.h
|
||
15 | ** CREATED: Thu Feb 25 09:19:00 WST 1999
|
||
16 | ** AUTHOR: Simon Cope
|
||
17 | ** PURPOSE: NCS Mutex handling.
|
||
18 | ** EDITS:
|
||
19 | ** [01] 03Nov00 ny Merged WinCE/PALM SDK changes
|
||
20 | ** [02] 12Apr01 ny Added copy constructor for CNCSMutex
|
||
21 | *******************************************************/
|
||
22 | |||
23 | #ifndef NCSMUTEX_H
|
||
24 | #define NCSMUTEX_H
|
||
25 | |||
26 | #ifdef __cplusplus
|
||
27 | extern "C" { |
||
28 | #endif
|
||
29 | |||
30 | #ifndef NCSDEFS_H
|
||
31 | #include "NCSDefs.h" |
||
32 | #endif
|
||
33 | #ifndef NCSTYPES_H
|
||
34 | #include "NCSTypes.h" |
||
35 | #endif
|
||
36 | #ifndef NCSTIMESTAMP_H
|
||
37 | #include "NCSTimeStamp.h" |
||
38 | #endif
|
||
39 | |||
40 | #ifdef POSIX
|
||
41 | #include <pthread.h> |
||
42 | #endif
|
||
43 | |||
44 | #if defined( MACINTOSH ) && defined( MAC_PREEMPTIVE )
|
||
45 | # include <Multiprocessing.h> |
||
46 | #endif
|
||
47 | |||
48 | typedef struct { |
||
49 | INT64 nLocks; /* Number of times mutex has been locked */
|
||
50 | INT64 nUnLocks; /* Number of times mutex has been unlocked */
|
||
51 | NCSTimeStampMs tsBeginTime; /* Time spent locking mutex */
|
||
52 | NCSTimeStampMs tsEndTime; /* Time spent unlocking mutex */
|
||
53 | NCSTimeStampMs tsTotalLockedTime; /* Total time spent locked */
|
||
54 | NCSTimeStampMs tsStartTemp; /* Temp to calculate tsTotalLockedTime */
|
||
55 | } NCSMutexStats; |
||
56 | |||
57 | typedef struct { |
||
58 | #ifdef WIN32
|
||
59 | CRITICAL_SECTION cs; |
||
60 | #elif defined MACINTOSH
|
||
61 | MPCriticalRegionID cs; |
||
62 | // FIXME: No mutex yet!
|
||
63 | #elif defined PALM
|
||
64 | // FIXME: No mutex yet!
|
||
65 | #elif defined POSIX
|
||
66 | pthread_mutex_t m; |
||
67 | #else /* PALM */ |
||
68 | ERROR: Define NCSMutex for this platform |
||
69 | #endif /* WIN32 */ |
||
70 | NCSMutexStats msStats; |
||
71 | BOOLEAN bCollectStats; |
||
72 | } NCSMutex; |
||
73 | |||
74 | typedef struct { |
||
75 | #ifdef WIN32
|
||
76 | HANDLE hLock; |
||
77 | #elif defined(PALM)
|
||
78 | int hLock;
|
||
79 | #elif defined(MACINTOSH)
|
||
80 | int hLock;
|
||
81 | #elif defined(POSIX)
|
||
82 | int hLock;
|
||
83 | #else /* WIN32 */ |
||
84 | #error NCSGlobalLockInfo
|
||
85 | #endif /* WIN32 */ |
||
86 | char *pLockName;
|
||
87 | } NCSGlobalLockInfo; |
||
88 | |||
89 | /*
|
||
90 | ** Defines.
|
||
91 | */
|
||
92 | #ifdef WIN32
|
||
93 | |||
94 | #define NCS_NULL_MUTEX { 0, 0, 0, 0, 0 } |
||
95 | |||
96 | #elif defined MACINTOSH
|
||
97 | |||
98 | #define NCS_NULL_MUTEX { 0, 0, 0, 0, 0 } |
||
99 | |||
100 | #elif defined SOLARIS
|
||
101 | |||
102 | #define NCS_NULL_MUTEX PTHREAD_MUTEX_INITIALIZER
|
||
103 | |||
104 | #elif defined HPUX
|
||
105 | |||
106 | #define NCS_NULL_MUTEX { PTHREAD_MUTEX_INITIALIZER }
|
||
107 | |||
108 | #elif defined LINUX
|
||
109 | |||
110 | #define NCS_NULL_MUTEX PTHREAD_MUTEX_INITIALIZER
|
||
111 | |||
112 | #elif defined MACOSX
|
||
113 | #define NCS_NULL_MUTEX PTHREAD_MUTEX_INITIALIZER
|
||
114 | |||
115 | #else /* MACINTOSH */ |
||
116 | |||
117 | ERROR: Define NCS_NULL_MUTEX for this platform |
||
118 | |||
119 | #endif /* WIN32 */ |
||
120 | |||
121 | /*
|
||
122 | ** Prototypes.
|
||
123 | */
|
||
124 | void NCSMutexInit(NCSMutex *pMutex);
|
||
125 | void NCSMutexFini(NCSMutex *pMutex);
|
||
126 | void NCSMutexBegin(NCSMutex *pMutex);
|
||
127 | void NCSMutexEnd(NCSMutex *pMutex);
|
||
128 | NCSMutexStats NCSMutexGetStats(NCSMutex *pMutex); |
||
129 | void NCSMutexEnableStats(NCSMutex *pMutex);
|
||
130 | void NCSMutexDisableStats(NCSMutex *pMutex);
|
||
131 | |||
132 | /* Global (SYSTEM Wide) Locks */
|
||
133 | void NCSGlobalLockInit(void); |
||
134 | void NCSGlobalLockFini(void); |
||
135 | NCSGlobalLockInfo *NCSGlobalLock(char *pLockName);
|
||
136 | void NCSGlobalUnlock(NCSGlobalLockInfo *pInfo);
|
||
137 | |||
138 | #ifdef __cplusplus
|
||
139 | } |
||
140 | |||
141 | #ifndef NCS_NO_UTIL_LINK
|
||
142 | // CNCSMutex
|
||
143 | class NCS_EXPORT CNCSMutex { |
||
144 | private:
|
||
145 | NCSMutex m_Mutex; |
||
146 | public:
|
||
147 | CNCSMutex(); |
||
148 | CNCSMutex(const CNCSMutex &mMutex); /**[02]**/ |
||
149 | virtual ~CNCSMutex(); |
||
150 | |||
151 | virtual void Lock(void); |
||
152 | virtual void UnLock(void); |
||
153 | }; |
||
154 | |||
155 | // CNCSMutexLock
|
||
156 | class NCS_EXPORT CNCSMutexLock { |
||
157 | |||
158 | private:
|
||
159 | CNCSMutex *m_pMutex; |
||
160 | public:
|
||
161 | CNCSMutexLock(CNCSMutex *pmMutex) { |
||
162 | if( pmMutex ) {
|
||
163 | m_pMutex = pmMutex; |
||
164 | m_pMutex->Lock(); |
||
165 | } else {
|
||
166 | m_pMutex = NULL;
|
||
167 | } |
||
168 | } |
||
169 | virtual ~CNCSMutexLock() { |
||
170 | if( m_pMutex ) {
|
||
171 | m_pMutex->UnLock(); |
||
172 | } |
||
173 | } |
||
174 | }; |
||
175 | |||
176 | #endif //NCS_NO_UTIL_LINK |
||
177 | |||
178 | #endif
|
||
179 | #endif /* NCSMUTEX_H */ |