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

  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           
 29 mday  1.3 
 30 mike  1.2 #define _WIN32_WINNT 0x0400
 31 mday  1.3 
 32 mike  1.2 #include <process.h>  
 33           
 34           //
 35           // PLEASE DO NOT REMOVE THE DEFINTION OF FD_SETSIZE!
 36           //
 37           
 38           #ifndef FD_SETSIZE
 39           # define FD_SETSIZE 1024
 40           #endif
 41           
 42           #include <windows.h>
 43 mday  1.3 #include <winbase.h>
 44 mike  1.2 #include <stdlib.h>
 45           #include <sys/types.h>
 46           #include <sys/timeb.h> 
 47           #include <errno.h>
 48           #include <Pegasus/Common/Config.h>
 49           
 50           
 51           typedef CRITICAL_SECTION  PEGASUS_CRIT_TYPE;
 52           typedef HANDLE  PEGASUS_SEMAPHORE_TYPE;
 53           typedef HANDLE  PEGASUS_THREAD_TYPE;
 54           typedef HANDLE  PEGASUS_MUTEX_TYPE;
 55           
 56           typedef struct {
 57                 PEGASUS_SEMAPHORE_TYPE  sem;
 58                 PEGASUS_THREAD_TYPE  owner;
 59           } PEGASUS_SEM_HANDLE ;
 60           
 61           typedef struct {
 62                 HANDLE  mut;
 63                 PEGASUS_THREAD_TYPE owner;
 64           } PEGASUS_MUTEX_HANDLE ;
 65 mike  1.2 
 66           
 67           typedef void *PEGASUS_CLEANUP_HANDLE;
 68           
 69           typedef DWORD PEGASUS_THREAD_RETURN;
 70           
 71           #define PTHREAD_MUTEX_TIMED_NP
 72           
 73           #define PEGASUS_THREAD_CDECL __stdcall
 74           
 75           typedef struct {
 76                 PEGASUS_THREAD_TYPE thid;
 77                 void * thatt;
 78           } PEGASUS_THREAD_HANDLE ;
 79           
 80           
 81           //-----------------------------------------------------------------
 82           /// Conditionals to support native conditional semaphore object
 83           //-----------------------------------------------------------------
 84           
 85           #if defined(PEGASUS_PLATFORM_WIN32_IX86_MSVC)
 86 mike  1.2 
 87 mday  1.3 #define PEGASUS_CONDITIONAL_NATIVE = 1 
 88           typedef HANDLE PEGASUS_COND_TYPE;
 89           
 90           typedef struct {
 91                 PEGASUS_COND_TYPE cond;
 92                 PEGASUS_THREAD_TYPE owner;
 93           } PEGASUS_COND_HANDLE;
 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           {
206 mday  1.4   _endthread(rc);
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           

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2