1 mike 1.2 //%////////////-*-c++-*-///////////////////////////////////////////////////////////
2 //
3 // Copyright (c) 2000, 2001 The Open group, BMC Software, Tivoli Systems, IBM
4 //
5 // Permission is hereby granted, free of charge, to any person obtaining a copy
6 // of this software and associated documentation files (the "Software"), to
7 // deal in the Software without restriction, including without limitation the
8 // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
9 // sell copies of the Software, and to permit persons to whom the Software is
10 // furnished to do so, subject to the following conditions:
11 //
12 // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
13 // ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED
14 // "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
15 // LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
16 // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
17 // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
18 // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
19 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20 //
21 //==============================================================================
22 mike 1.2 //
23 // Author: Mike Day (mdday@us.ibm.com)
24 //
25 // Modified By:
26 //
27 //%/////////////////////////////////////////////////////////////////////////////
28
|
94 mike 1.2
95 #endif // platform conditional type
96
97 //-----------------------------------------------------------------
98 /// Conditionals to support native or generic atomic variables
99 //-----------------------------------------------------------------
100
101 #if defined(PEGASUS_PLATFORM_WIN32_IX86_MSVC)
102 #define PEGASUS_ATOMIC_INT_NATIVE = 1
103
104 typedef LONG PEGASUS_ATOMIC_TYPE ;
105
106 #endif // platform atomic type
107
108 //-----------------------------------------------------------------
109 /// Conditionals to support native or generic read/write semaphores
110 //-----------------------------------------------------------------
111
112 #if defined(PEGASUS_PLATFORM_WIN32_IX86_MSVC)
113
114 // no native rw lock for windows -- use the generic one
115 mike 1.2
116 #endif // platform read/write type
117
118
119 //struct timeval
120 //{
121 // long int tv_sec; long int tv_usec;
122 //};
123
124 struct timezone
125 {
126 int tz_minuteswest;
127 int tz_dsttime;
128 };
129
130
131 inline int pegasus_gettimeofday(struct timeval *tv)
132 {
133 struct _timeb timebuffer;
134 if (tv == NULL)
135 return(-1);
136 mike 1.2 _ftime( &timebuffer );
137 tv->tv_sec = timebuffer.time;
138 tv->tv_usec = ( timebuffer.millitm * 1000 );
139 return(0);
140 }
141
142 inline int PEGASUS_COMMON_LINKAGE gettimeofday(struct timeval *tv, struct timezone *tz)
143 {
144 return(pegasus_gettimeofday(tv));
145 }
146
147 PEGASUS_NAMESPACE_BEGIN
148
149 inline PEGASUS_COMMON_LINKAGE void pegasus_yield(void)
150 {
151 Sleep(0);
152 }
153
154 // pthreads cancellation calls
155 inline PEGASUS_COMMON_LINKAGE void disable_cancel(void)
156 {
157 mike 1.2 ;
158 }
159
160 inline PEGASUS_COMMON_LINKAGE void enable_cancel(void)
161 {
162 ;
163 }
164
165
166 // Windows does not have equivalent functionality with Unix-like
167 // operating systems. Be careful using these next two
168 // macros. There is no pop routine in windows. Further, windows
169 // does not allow passing parameters to exit functions. !!
170 inline PEGASUS_COMMON_LINKAGE void native_cleanup_push( void (*)(void *), void *) { ; }
171
172 inline PEGASUS_COMMON_LINKAGE void native_cleanup_pop(Boolean) { ; }
173
174 inline void PEGASUS_COMMON_LINKAGE init_crit(PEGASUS_CRIT_TYPE *crit)
175 {
176 InitializeCriticalSection(crit);
177 }
178 mike 1.2
179 inline void PEGASUS_COMMON_LINKAGE enter_crit(PEGASUS_CRIT_TYPE *crit)
180 {
181 EnterCriticalSection(crit);
182 }
183
184 inline void PEGASUS_COMMON_LINKAGE try_crit(PEGASUS_CRIT_TYPE *crit)
185 {
186 EnterCriticalSection(crit);
187 }
188
189 inline void PEGASUS_COMMON_LINKAGE exit_crit(PEGASUS_CRIT_TYPE *crit)
190 {
191 LeaveCriticalSection(crit);
192 }
193
194 inline void PEGASUS_COMMON_LINKAGE destroy_crit(PEGASUS_CRIT_TYPE *crit)
195 {
196 DeleteCriticalSection(crit);
197 }
198
199 mike 1.2 inline PEGASUS_THREAD_TYPE PEGASUS_COMMON_LINKAGE pegasus_thread_self(void)
200 {
201 return((PEGASUS_THREAD_TYPE)GetCurrentThreadId());
202 }
203
204 inline void PEGASUS_COMMON_LINKAGE exit_thread(PEGASUS_THREAD_RETURN rc)
205 {
|
207 mike 1.2 }
208
209 inline void PEGASUS_COMMON_LINKAGE pegasus_sleep(int ms)
210 {
211 if(ms == 0)
212 {
213 Sleep(0);
214 return;
215 }
216
217 struct _timeb end, now;
218 _ftime( &end );
219 end.time += (ms / 1000);
220 ms -= (ms / 1000);
221 end.millitm += ms;
222
223 do
224 {
225 Sleep(0);
226 _ftime(&now);
227
228 mike 1.2 } while( end.millitm > now.millitm && end.time >= now.time);
229 }
230
231
232 inline void PEGASUS_COMMON_LINKAGE destroy_thread(PEGASUS_THREAD_TYPE th, PEGASUS_THREAD_RETURN rc)
233 {
234 TerminateThread(th, rc);
235 }
236
237
238 PEGASUS_NAMESPACE_END
239
240
241
|