1 //%2003////////////////////////////////////////////////////////////////////////
3 // 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.
8 // Permission is hereby granted, free of charge, to any person obtaining a copy
9 // 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 // sell copies of the Software, and to permit persons to whom the Software is
13 // furnished to do so, subject to the following conditions:
15 // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
16 // 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 // 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 // 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.
24 //==============================================================================
30 //%/////////////////////////////////////////////////////////////////////////////
32 #ifndef IPC_AIX_include
33 #define IPC_AIX_include
37 #include <semaphore.h>
42 PEGASUS_NAMESPACE_BEGIN
44 typedef sem_t PEGASUS_SEMAPHORE_TYPE;
45 typedef pthread_t PEGASUS_THREAD_TYPE;
46 typedef pthread_mutex_t PEGASUS_MUTEX_TYPE;
50 pthread_mutex_t mutex;
52 PEGASUS_THREAD_TYPE owner;
53 } PEGASUS_SEM_HANDLE ;
57 pthread_mutexattr_t mutatt;
59 } PEGASUS_MUTEX_HANDLE ;
61 typedef PEGASUS_MUTEX_HANDLE PEGASUS_CRIT_TYPE;
63 typedef void *PEGASUS_CLEANUP_HANDLE ;
64 typedef void *PEGASUS_THREAD_RETURN;
66 #define PEGASUS_THREAD_CDECL
71 } PEGASUS_THREAD_HANDLE ;
73 //-----------------------------------------------------------------
74 /// Conditionals to support native or generic Conditional Semaphore
75 //-----------------------------------------------------------------
77 #define PEGASUS_CONDITIONAL_NATIVE = 1
79 typedef pthread_cond_t PEGASUS_COND_TYPE;
84 } PEGASUS_COND_HANDLE;
87 //-----------------------------------------------------------------
88 /// Conditionals to support native or generic atomic variables
89 //-----------------------------------------------------------------
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
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.
99 // #define PEGASUS_ATOMIC_INT_NATIVE = 1
101 // typedef sig_atomic_t PEGASUS_ATOMIC_TYPE ;
104 //-----------------------------------------------------------------
105 /// Conditionals to support native or generic read/write semaphores
106 //-----------------------------------------------------------------
108 #define PEGASUS_READWRITE_NATIVE = 1
111 pthread_rwlock_t rwlock;
113 } PEGASUS_RWLOCK_HANDLE;
116 //PEGASUS_NAMESPACE_BEGIN
117 inline void pegasus_yield(void)
123 // pthreads cancellation calls
124 inline void disable_cancel(void)
126 pthread_setcanceltype(PTHREAD_CANCEL_DISABLE, NULL);
129 inline void enable_cancel(void)
131 pthread_setcanceltype(PTHREAD_CANCEL_DISABLE, NULL);
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 // these ALSO SET CANCEL STATE TO DEFER
139 //#define native_cleanup_push( func, arg ) \
140 // pthread_cleanup_push_defer_np((func), arg)
143 // native cleanup_pop(Boolean execute) ;
144 //#define native_cleanup_pop(execute) \
145 // pthread_cleanup_pop_restore_np(execute)
147 inline void pegasus_sleep(int msec)
149 struct timespec wait;
150 wait.tv_sec = msec / 1000;
151 wait.tv_nsec = (msec % 1000) * 1000000;
152 nanosleep(&wait, NULL);
155 inline void init_crit(PEGASUS_CRIT_TYPE *crit)
157 pthread_mutex_init(&(crit->mut), NULL);
160 inline void enter_crit(PEGASUS_CRIT_TYPE *crit)
162 pthread_mutex_lock(&(crit->mut));
165 inline void try_crit(PEGASUS_CRIT_TYPE *crit)
167 pthread_mutex_trylock(&(crit->mut));
170 inline void exit_crit(PEGASUS_CRIT_TYPE *crit)
172 pthread_mutex_unlock(&(crit->mut));
175 inline void destroy_crit(PEGASUS_CRIT_TYPE *crit)
177 pthread_mutexattr_destroy(&(crit->mutatt));
180 static inline int pegasus_gettimeofday(struct timeval *tv) { return(gettimeofday(tv, NULL)); }
182 inline void exit_thread(PEGASUS_THREAD_RETURN rc)
187 inline PEGASUS_THREAD_TYPE pegasus_thread_self(void)
189 return(pthread_self());
193 typedef pthread_key_t PEGASUS_THREAD_KEY_TYPE;
195 inline Uint32 pegasus_key_create(PEGASUS_THREAD_KEY_TYPE * key)
197 // Note: a destructor is not supported
198 // (because not supported on Windows (?))
199 return pthread_key_create(key, NULL);
202 inline Uint32 pegasus_key_delete(PEGASUS_THREAD_KEY_TYPE key)
204 return pthread_key_delete(key);
207 inline void * pegasus_get_thread_specific(PEGASUS_THREAD_KEY_TYPE key)
209 return pthread_getspecific(key);
212 inline Uint32 pegasus_set_thread_specific(PEGASUS_THREAD_KEY_TYPE key,
215 return pthread_setspecific(key, value);
219 inline void destroy_thread(PEGASUS_THREAD_TYPE th, PEGASUS_THREAD_RETURN rc)
225 PEGASUS_NAMESPACE_END
227 #endif // IPCAIXInclude