1 karl 1.22 //%2005////////////////////////////////////////////////////////////////////////
|
2 mike 1.2 //
|
3 karl 1.21 // Copyright (c) 2000, 2001, 2002 BMC Software; Hewlett-Packard Development
4 // Company, L.P.; IBM Corp.; The Open Group; Tivoli Systems.
5 // Copyright (c) 2003 BMC Software; Hewlett-Packard Development Company, L.P.;
|
6 karl 1.19 // IBM Corp.; EMC Corporation, The Open Group.
|
7 karl 1.21 // Copyright (c) 2004 BMC Software; Hewlett-Packard Development Company, L.P.;
8 // IBM Corp.; EMC Corporation; VERITAS Software Corporation; The Open Group.
|
9 karl 1.22 // Copyright (c) 2005 Hewlett-Packard Development Company, L.P.; IBM Corp.;
10 // EMC Corporation; VERITAS Software Corporation; The Open Group.
|
11 mike 1.2 //
12 // Permission is hereby granted, free of charge, to any person obtaining a copy
|
13 kumpf 1.11 // of this software and associated documentation files (the "Software"), to
14 // deal in the Software without restriction, including without limitation the
15 // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
16 mike 1.2 // sell copies of the Software, and to permit persons to whom the Software is
17 // furnished to do so, subject to the following conditions:
|
18 mday 1.7 //
|
19 kumpf 1.11 // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
|
20 mike 1.2 // ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED
21 // "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
|
22 kumpf 1.11 // LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
23 // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
24 // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
|
25 mike 1.2 // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 //
28 //==============================================================================
29 //
30 // Author: Mike Day (mdday@us.ibm.com)
31 //
|
32 sage 1.9 // Modified By: Arthur Pichlkostner
33 // (checked in: Markus Mueller sedgewick_de@yahoo.de)
|
34 mary 1.10 // Mary Hinton (m.hinton@verizon.net)
|
35 s.hills 1.18 // Steve Hills (steve.hills@ncr.com)
|
36 mike 1.2 //%/////////////////////////////////////////////////////////////////////////////
37
|
38 mday 1.3
|
39 mike 1.2 #define _WIN32_WINNT 0x0400
|
40 mday 1.3
|
41 mday 1.7 #include <process.h>
|
42 mike 1.2
43 //
44 // PLEASE DO NOT REMOVE THE DEFINTION OF FD_SETSIZE!
45 //
46
47 #ifndef FD_SETSIZE
48 # define FD_SETSIZE 1024
49 #endif
50
51 #include <windows.h>
|
52 tony 1.15 #ifndef _WINSOCKAPI_
53 #include <winsock2.h>
54 #endif
|
55 mday 1.3 #include <winbase.h>
|
56 mike 1.2 #include <stdlib.h>
57 #include <sys/types.h>
|
58 mday 1.7 #include <sys/timeb.h>
|
59 mike 1.2 #include <errno.h>
60 #include <Pegasus/Common/Config.h>
|
61 mday 1.14 #include <Pegasus/Common/Linkage.h>
|
62 mike 1.2
63
64 typedef CRITICAL_SECTION PEGASUS_CRIT_TYPE;
65 typedef HANDLE PEGASUS_SEMAPHORE_TYPE;
66 typedef HANDLE PEGASUS_THREAD_TYPE;
67 typedef HANDLE PEGASUS_MUTEX_TYPE;
68
69 typedef struct {
70 PEGASUS_SEMAPHORE_TYPE sem;
71 PEGASUS_THREAD_TYPE owner;
72 } PEGASUS_SEM_HANDLE ;
73
74 typedef struct {
75 HANDLE mut;
76 PEGASUS_THREAD_TYPE owner;
77 } PEGASUS_MUTEX_HANDLE ;
78
79
80 typedef void *PEGASUS_CLEANUP_HANDLE;
81
|
82 s.hills 1.18 typedef unsigned PEGASUS_THREAD_RETURN;
|
83 mike 1.2
84 #define PTHREAD_MUTEX_TIMED_NP
85
86 #define PEGASUS_THREAD_CDECL __stdcall
87
88 typedef struct {
89 PEGASUS_THREAD_TYPE thid;
90 void * thatt;
91 } PEGASUS_THREAD_HANDLE ;
92
93
94 //-----------------------------------------------------------------
95 /// Conditionals to support native conditional semaphore object
96 //-----------------------------------------------------------------
97
98 #if defined(PEGASUS_PLATFORM_WIN32_IX86_MSVC)
99
|
100 kumpf 1.20 #define PEGASUS_CONDITIONAL_NATIVE
|
101 mday 1.3 typedef HANDLE PEGASUS_COND_TYPE;
102
103 typedef struct {
104 PEGASUS_COND_TYPE cond;
105 PEGASUS_THREAD_TYPE owner;
106 } PEGASUS_COND_HANDLE;
|
107 mike 1.2
108 #endif // platform conditional type
109
110 //-----------------------------------------------------------------
111 /// Conditionals to support native or generic atomic variables
112 //-----------------------------------------------------------------
113
114 #if defined(PEGASUS_PLATFORM_WIN32_IX86_MSVC)
|
115 kumpf 1.20 #define PEGASUS_ATOMIC_INT_NATIVE
|
116 mike 1.2
117 typedef LONG PEGASUS_ATOMIC_TYPE ;
118
119 #endif // platform atomic type
120
121 //-----------------------------------------------------------------
122 /// Conditionals to support native or generic read/write semaphores
123 //-----------------------------------------------------------------
124
125 #if defined(PEGASUS_PLATFORM_WIN32_IX86_MSVC)
126
|
127 mday 1.7 // no native rw lock for windows -- use the generic one
|
128 mike 1.2
129 #endif // platform read/write type
130
131
|
132 mday 1.7 //struct timeval
|
133 mike 1.2 //{
134 // long int tv_sec; long int tv_usec;
135 //};
136
137 struct timezone
138 {
139 int tz_minuteswest;
140 int tz_dsttime;
141 };
142
143
|
144 sage 1.9 // excluded
|
145 mday 1.13
|
146 mike 1.2 inline int pegasus_gettimeofday(struct timeval *tv)
147 {
|
148 mday 1.7 struct _timeb timebuffer;
|
149 mike 1.2 if (tv == NULL)
150 return(-1);
151 _ftime( &timebuffer );
152 tv->tv_sec = timebuffer.time;
153 tv->tv_usec = ( timebuffer.millitm * 1000 );
154 return(0);
|
155 mday 1.13 }
|
156 sage 1.9
157 // Markus: new implementation with higher resolution
158 // that is needed for performance statistics
|
159 mday 1.13 /*
160
161
|
162 sage 1.9
|
163 mday 1.13 THIS ROUTINE IS BROKEN << Thu Mar 20 10:24:14 2003 mdd >>
|
164 sage 1.9 inline int pegasus_gettimeofday(struct timeval *tv)
165 {
166 if (tv == NULL){
167 return(-1);
168 }
169 LARGE_INTEGER frequency;
170 if (!QueryPerformanceFrequency(&frequency)){
171 struct _timeb timebuffer;
172 _ftime( &timebuffer );
173 tv->tv_sec = timebuffer.time;
174 tv->tv_usec = ( timebuffer.millitm * 1000 );
175 return(0);
176 } else {
177 LARGE_INTEGER counter;
178 QueryPerformanceCounter(&counter);
|
179 mary 1.10 tv->tv_sec = (__int64)((counter.QuadPart)/(frequency.QuadPart));
180 tv->tv_usec = ((__int64)
|
181 sage 1.9 ((counter.QuadPart)*1000000/(frequency.QuadPart)))%1000000;
182 return(0);
183 }
|
184 mike 1.2 }
185
|
186 mday 1.13 */
|
187 mike 1.2 inline int PEGASUS_COMMON_LINKAGE gettimeofday(struct timeval *tv, struct timezone *tz)
188 {
189 return(pegasus_gettimeofday(tv));
190 }
191
192 PEGASUS_NAMESPACE_BEGIN
193
194 inline PEGASUS_COMMON_LINKAGE void pegasus_yield(void)
195 {
196 Sleep(0);
197 }
198
|
199 mday 1.7 // pthreads cancellation calls
|
200 mike 1.2 inline PEGASUS_COMMON_LINKAGE void disable_cancel(void)
201 {
202 ;
203 }
204
205 inline PEGASUS_COMMON_LINKAGE void enable_cancel(void)
206 {
207 ;
208 }
209
210
211 // Windows does not have equivalent functionality with Unix-like
|
212 mday 1.7 // operating systems. Be careful using these next two
|
213 mike 1.2 // macros. There is no pop routine in windows. Further, windows
214 // does not allow passing parameters to exit functions. !!
215 inline PEGASUS_COMMON_LINKAGE void native_cleanup_push( void (*)(void *), void *) { ; }
216
217 inline PEGASUS_COMMON_LINKAGE void native_cleanup_pop(Boolean) { ; }
218
219 inline void PEGASUS_COMMON_LINKAGE init_crit(PEGASUS_CRIT_TYPE *crit)
220 {
221 InitializeCriticalSection(crit);
222 }
223
224 inline void PEGASUS_COMMON_LINKAGE enter_crit(PEGASUS_CRIT_TYPE *crit)
225 {
226 EnterCriticalSection(crit);
227 }
228
229 inline void PEGASUS_COMMON_LINKAGE try_crit(PEGASUS_CRIT_TYPE *crit)
230 {
|
231 mday 1.7 EnterCriticalSection(crit);
|
232 mike 1.2 }
233
234 inline void PEGASUS_COMMON_LINKAGE exit_crit(PEGASUS_CRIT_TYPE *crit)
235 {
236 LeaveCriticalSection(crit);
237 }
238
239 inline void PEGASUS_COMMON_LINKAGE destroy_crit(PEGASUS_CRIT_TYPE *crit)
240 {
241 DeleteCriticalSection(crit);
242 }
243
|
244 mday 1.7 inline PEGASUS_THREAD_TYPE PEGASUS_COMMON_LINKAGE pegasus_thread_self(void)
245 {
|
246 mike 1.2 return((PEGASUS_THREAD_TYPE)GetCurrentThreadId());
247 }
248
|
249 chuck 1.16 // l10n start
|
250 chuck 1.17 typedef DWORD PEGASUS_THREAD_KEY_TYPE;
|
251 chuck 1.16
252 inline Uint32 pegasus_key_create(PEGASUS_THREAD_KEY_TYPE * key)
253 {
254 // Note: destructor is not supported
255 *key = TlsAlloc();
256 if (*key == -1)
257 return 1;
258 return 0;
259 }
260
261 inline Uint32 pegasus_key_delete(PEGASUS_THREAD_KEY_TYPE key)
262 {
263 if (TlsFree(key))
264 return 0;
265 return 1;
266 }
267
268 inline void * pegasus_get_thread_specific(PEGASUS_THREAD_KEY_TYPE key)
269 {
270 return TlsGetValue(key);
271 }
272 chuck 1.16
273 inline Uint32 pegasus_set_thread_specific(PEGASUS_THREAD_KEY_TYPE key,
274 void * value)
275 {
276 if (TlsSetValue(key, value))
277 return 0;
278 return 1;
279 }
280 // l10n end
281
|
282 mike 1.2 inline void PEGASUS_COMMON_LINKAGE exit_thread(PEGASUS_THREAD_RETURN rc)
283 {
|
284 mday 1.8 _endthreadex(rc);
|
285 mike 1.2 }
286
287 inline void PEGASUS_COMMON_LINKAGE pegasus_sleep(int ms)
288 {
289 if(ms == 0)
290 {
291 Sleep(0);
292 return;
293 }
|
294 mday 1.7
|
295 mike 1.2 struct _timeb end, now;
296 _ftime( &end );
297 end.time += (ms / 1000);
298 ms -= (ms / 1000);
299 end.millitm += ms;
300
|
301 mday 1.7 do
|
302 mike 1.2 {
303 Sleep(0);
304 _ftime(&now);
|
305 mday 1.7
|
306 mike 1.2 } while( end.millitm > now.millitm && end.time >= now.time);
307 }
308
309
310 inline void PEGASUS_COMMON_LINKAGE destroy_thread(PEGASUS_THREAD_TYPE th, PEGASUS_THREAD_RETURN rc)
311 {
312 TerminateThread(th, rc);
313 }
314
315
316 PEGASUS_NAMESPACE_END
317
318
319
|