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

  1 karl  1.7 //%2003////////////////////////////////////////////////////////////////////////
  2 sage  1.1 //
  3 karl  1.7 // 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           // IBM Corp.; EMC Corporation, The Open Group.
  7 sage  1.1 //
  8           // Permission is hereby granted, free of charge, to any person obtaining a copy
  9 kumpf 1.3 // of this software and associated documentation files (the "Software"), to
 10           // deal in the Software without restriction, including without limitation the
 11           // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
 12 sage  1.1 // sell copies of the Software, and to permit persons to whom the Software is
 13           // furnished to do so, subject to the following conditions:
 14           // 
 15 kumpf 1.3 // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
 16 sage  1.1 // ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED
 17           // "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
 18 kumpf 1.3 // LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
 19           // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
 20           // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
 21 sage  1.1 // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
 22           // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 23           //
 24           //==============================================================================
 25           //
 26           // Author: 
 27           //
 28           // Modified By:
 29           //
 30           //%/////////////////////////////////////////////////////////////////////////////
 31           
 32           #ifndef IPC_AIX_include
 33           #define IPC_AIX_include
 34           
 35           #include <sched.h>
 36           #include <pthread.h>
 37           #include <semaphore.h>
 38           #include <signal.h>
 39           #include <errno.h>
 40           #include <sys/time.h>
 41           #include <time.h>
 42 sage  1.2 PEGASUS_NAMESPACE_BEGIN
 43 sage  1.1 
 44           typedef sem_t PEGASUS_SEMAPHORE_TYPE;
 45           typedef pthread_t PEGASUS_THREAD_TYPE;
 46           typedef pthread_mutex_t PEGASUS_MUTEX_TYPE;
 47           
 48           typedef struct {
 49               Uint32 waiters;
 50               pthread_mutex_t mutex;
 51               pthread_cond_t cond;
 52               PEGASUS_THREAD_TYPE owner;
 53           } PEGASUS_SEM_HANDLE ;
 54           
 55           typedef struct {
 56               pthread_mutex_t mut;
 57               pthread_mutexattr_t mutatt;
 58               pthread_t owner;
 59           } PEGASUS_MUTEX_HANDLE ;
 60           
 61           typedef PEGASUS_MUTEX_HANDLE PEGASUS_CRIT_TYPE;
 62           
 63           typedef void *PEGASUS_CLEANUP_HANDLE ;
 64 sage  1.1 typedef void *PEGASUS_THREAD_RETURN;
 65           
 66           #define PEGASUS_THREAD_CDECL
 67           
 68           typedef struct {
 69               pthread_t thid;
 70               pthread_attr_t thatt;
 71           } PEGASUS_THREAD_HANDLE ;
 72           
 73           //-----------------------------------------------------------------
 74           /// Conditionals to support native or generic Conditional Semaphore
 75           //-----------------------------------------------------------------
 76           
 77 kumpf 1.8 #define PEGASUS_CONDITIONAL_NATIVE
 78 sage  1.1 
 79           typedef pthread_cond_t PEGASUS_COND_TYPE;
 80           
 81           typedef struct {
 82               pthread_cond_t cond;
 83               pthread_t owner;
 84           } PEGASUS_COND_HANDLE;
 85           
 86           
 87           //-----------------------------------------------------------------
 88           /// Conditionals to support native or generic atomic variables
 89           //-----------------------------------------------------------------
 90           
 91           // linux offers a built-in integer type for atomic access
 92           // other unix platforms HPUX, AIX, may have different types
 93           // implementors should use the native type for faster operations
 94           
 95           // ATTN: RK - sig_atomic_t is defined on HP-UX, but the atomic_read()
 96           // and atomic_write() methods are not defined.  Use the non-native
 97           // implementation for now.
 98           
 99 kumpf 1.8 // #define PEGASUS_ATOMIC_INT_NATIVE
100 sage  1.1 
101           // typedef sig_atomic_t PEGASUS_ATOMIC_TYPE ;
102           
103           
104           //-----------------------------------------------------------------
105           /// Conditionals to support native or generic read/write semaphores
106           //-----------------------------------------------------------------
107           
108 kumpf 1.8 #define PEGASUS_READWRITE_NATIVE
109 sage  1.1 
110           typedef struct {
111               pthread_rwlock_t rwlock;
112               pthread_t owner;
113           } PEGASUS_RWLOCK_HANDLE;
114           
115           
116 sage  1.2 //PEGASUS_NAMESPACE_BEGIN
117 sage  1.1 inline void pegasus_yield(void)
118           {
119                 sched_yield();
120           }
121           
122           
123           // pthreads cancellation calls 
124           inline void disable_cancel(void)
125           {
126              pthread_setcanceltype(PTHREAD_CANCEL_DISABLE, NULL);
127           }
128           
129           inline void enable_cancel(void)
130           {
131              pthread_setcanceltype(PTHREAD_CANCEL_DISABLE, NULL);
132           }
133           
134           
135           // the next two routines are macros that MUST SHARE the same stack frame
136           // they are implemented as macros by glibc. 
137           // native_cleanup_push( void (*func)(void *) ) ;
138 sage  1.1 // these ALSO SET CANCEL STATE TO DEFER
139 sage  1.4 //#define native_cleanup_push( func, arg ) \
140           //   pthread_cleanup_push_defer_np((func), arg)
141           
142 sage  1.1 
143           // native cleanup_pop(Boolean execute) ; 
144 sage  1.4 //#define native_cleanup_pop(execute) \
145           //   pthread_cleanup_pop_restore_np(execute)
146 sage  1.1 
147           inline void pegasus_sleep(int msec)
148           {
149               struct timespec wait;
150               wait.tv_sec = msec / 1000;
151 kumpf 1.5     wait.tv_nsec = (msec % 1000) * 1000000;
152 sage  1.1     nanosleep(&wait, NULL);
153           }
154           
155           inline void init_crit(PEGASUS_CRIT_TYPE *crit)
156           {
157              pthread_mutex_init(&(crit->mut), NULL);
158           }
159           
160           inline void enter_crit(PEGASUS_CRIT_TYPE *crit)
161           {
162              pthread_mutex_lock(&(crit->mut));
163           }
164           
165           inline void try_crit(PEGASUS_CRIT_TYPE *crit)
166           {
167              pthread_mutex_trylock(&(crit->mut));
168           }
169           
170           inline void exit_crit(PEGASUS_CRIT_TYPE *crit)
171           {
172              pthread_mutex_unlock(&(crit->mut));
173 sage  1.1 }
174           
175           inline void destroy_crit(PEGASUS_CRIT_TYPE *crit)
176           {
177              pthread_mutexattr_destroy(&(crit->mutatt));
178           }
179           
180           static inline int pegasus_gettimeofday(struct timeval *tv) { return(gettimeofday(tv, NULL)); }
181           
182           inline void exit_thread(PEGASUS_THREAD_RETURN rc)
183           {
184             pthread_exit(rc);
185           }
186           
187           inline PEGASUS_THREAD_TYPE pegasus_thread_self(void) 
188           { 
189              return(pthread_self());
190           }
191           
192 chuck 1.6 // l10n start
193           typedef pthread_key_t PEGASUS_THREAD_KEY_TYPE;
194           
195           inline Uint32 pegasus_key_create(PEGASUS_THREAD_KEY_TYPE * key)
196           {
197           	// Note: a destructor is not supported 
198           	// (because not supported on Windows (?))
199           	return pthread_key_create(key, NULL);
200           } 
201           
202           inline Uint32 pegasus_key_delete(PEGASUS_THREAD_KEY_TYPE key)
203           {
204           	return pthread_key_delete(key);
205           } 
206           
207           inline void * pegasus_get_thread_specific(PEGASUS_THREAD_KEY_TYPE key)
208           {
209           	return pthread_getspecific(key);
210           } 
211           
212           inline Uint32 pegasus_set_thread_specific(PEGASUS_THREAD_KEY_TYPE key,
213 chuck 1.6 										 void * value)
214           {
215           	return pthread_setspecific(key, value);
216           } 
217           // l10n end
218           
219 sage  1.1 inline void destroy_thread(PEGASUS_THREAD_TYPE th, PEGASUS_THREAD_RETURN rc)
220           {
221              pthread_cancel(th);
222           }
223           
224           
225           PEGASUS_NAMESPACE_END
226           
227           #endif // IPCAIXInclude

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2