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

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

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2