(file) Return to IPCWindows.h CVS log (file) (dir) Up to [Pegasus] / pegasus / src / Pegasus / Common

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

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2