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

  1 karl  1.11 //%2005////////////////////////////////////////////////////////////////////////
  2 sage  1.1  //
  3 karl  1.10 // 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.10 // 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.11 // Copyright (c) 2005 Hewlett-Packard Development Company, L.P.; IBM Corp.;
 10            // EMC Corporation; VERITAS Software Corporation; The Open Group.
 11 sage  1.1  //
 12            // Permission is hereby granted, free of charge, to any person obtaining a copy
 13 sage  1.2  // of this software and associated documentation files (the "Software"), to
 14            // deal in the Software without restriction, including without limitation the
 15            // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
 16 sage  1.1  // sell copies of the Software, and to permit persons to whom the Software is
 17            // furnished to do so, subject to the following conditions:
 18 kumpf 1.3  // 
 19 sage  1.2  // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
 20 sage  1.1  // ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED
 21            // "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
 22 sage  1.2  // LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
 23            // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
 24            // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
 25 sage  1.1  // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
 26            // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 27            //
 28            //==============================================================================
 29            //
 30            // Author: Markus Mueller (sedgewick_de@yahoo.de)
 31            //
 32            // Modified By: Mike Day (mdday@us.ibm.com)
 33            //
 34            //%/////////////////////////////////////////////////////////////////////////////
 35            
 36 sage  1.2  #ifndef IPC_ZOS_include
 37            #define IPC_ZOS_include
 38 sage  1.1  
 39            //#include <sched.h>
 40            //#include <semaphore.h>
 41            #include <pthread.h>
 42            #include <signal.h>
 43            #include <errno.h>
 44            #include <sys/time.h>
 45            #include <time.h>
 46            //#include <sys/timex.h>
 47            #include <unistd.h>
 48            
 49            #define SEM_VALUE_MAX 0xffffffff
 50            
 51            
 52            PEGASUS_NAMESPACE_BEGIN
 53            
 54            //typedef sem_t PEGASUS_SEMAPHORE_TYPE;
 55            //typedef pthread_t PEGASUS_THREAD_TYPE;
 56 sage  1.2  
 57 sage  1.1  typedef PEGASUS_UINT64 PEGASUS_THREAD_TYPE;
 58            typedef pthread_mutex_t PEGASUS_MUTEX_TYPE;
 59            
 60            typedef struct {
 61                Uint32 waiters;
 62                pthread_mutex_t mutex;
 63                pthread_cond_t cond;
 64                PEGASUS_THREAD_TYPE owner;
 65            } PEGASUS_SEM_HANDLE ;
 66            
 67            typedef struct {
 68                pthread_mutex_t mut;
 69                pthread_mutexattr_t mutatt;
 70                PEGASUS_THREAD_TYPE owner;
 71            } PEGASUS_MUTEX_HANDLE ;
 72            
 73 sage  1.2  typedef PEGASUS_MUTEX_HANDLE PEGASUS_CRIT_TYPE;
 74            
 75            
 76 sage  1.1  struct _pthread_cleanup_buffer {
 77                void (*__routine) (void *);             /* Function to call.  */
 78                void *__arg;                            /* Its argument.  */
 79                int __canceltype;                       /* Saved cancellation type. */
 80                struct _pthread_cleanup_buffer *__prev;  /* Chaining of cleanup functions.*/
 81            };
 82            typedef struct _pthread_cleanup_buffer  PEGASUS_CLEANUP_HANDLE;
 83            
 84 sage  1.2  //#define PEGASUS_THREAD_CDECL __cdecl
 85            #define PEGASUS_THREAD_CDECL
 86            
 87 sage  1.1  typedef void *PEGASUS_THREAD_RETURN;
 88            
 89            typedef struct {
 90                PEGASUS_THREAD_TYPE thid;
 91                pthread_attr_t thatt;
 92            } PEGASUS_THREAD_HANDLE ;
 93            
 94            //-----------------------------------------------------------------
 95            /// Conditionals to support native or generic Conditional Semaphore
 96            //-----------------------------------------------------------------
 97            
 98 kumpf 1.8  #define PEGASUS_CONDITIONAL_NATIVE
 99 sage  1.1  
100            typedef pthread_cond_t PEGASUS_COND_TYPE;
101            
102            typedef struct {
103                pthread_cond_t cond;
104                PEGASUS_THREAD_TYPE owner;
105            } PEGASUS_COND_HANDLE;
106            
107            //-----------------------------------------------------------------
108            /// Conditionals to support native or generic atomic variables
109            //-----------------------------------------------------------------
110            
111            
112            //-----------------------------------------------------------------
113            /// Conditionals to support native or generic read/write semaphores
114            //-----------------------------------------------------------------
115            
116 kumpf 1.8  #define PEGASUS_READWRITE_NATIVE
117 sage  1.1  
118 sage  1.2  typedef struct {
119                 pthread_rwlock_t rwlock;
120                 PEGASUS_THREAD_TYPE owner;
121            } PEGASUS_RWLOCK_HANDLE;
122 sage  1.1  
123            
124            inline void pegasus_yield(void)
125            {
126                  pthread_yield(NULL);
127            }
128            
129 sage  1.2  // pthreads cancellation calls
130 sage  1.1  inline void disable_cancel(void)
131            {
132               pthread_setintr(PTHREAD_INTR_DISABLE);
133            }
134            
135            inline void enable_cancel(void)
136            {
137               pthread_setintr(PTHREAD_INTR_ENABLE);
138            }
139            
140            inline void pegasus_sleep(int msec)
141            {
142 marek 1.9  	int seconds;
143            	int microsecs = msec * 1000; /* convert from milliseconds to microseconds */
144            
145            	if (microsecs < 1000000)
146            	{
147            		usleep(microsecs/2);
148                    pthread_testintr();
149            		usleep(microsecs/2);
150            
151            	}
152            	else
153            	{
154            		// sleep for loop seconds
155            		seconds = microsecs / 1000000;
156            		sleep(seconds);
157            		// Usleep the remaining time
158            		if ((seconds*1000000) < microsecs)
159            		usleep(microsecs - (seconds*1000000));
160            	}
161 sage  1.1  }
162            
163            inline void init_crit(PEGASUS_CRIT_TYPE *crit)
164            {
165 sage  1.2     pthread_mutex_init(&(crit->mut), NULL);
166 sage  1.1  }
167            
168            inline void enter_crit(PEGASUS_CRIT_TYPE *crit)
169            {
170 sage  1.2     pthread_mutex_lock(&(crit->mut));
171 sage  1.1  }
172            
173            inline void try_crit(PEGASUS_CRIT_TYPE *crit)
174            {
175 sage  1.2     pthread_mutex_trylock(&(crit->mut));
176 sage  1.1  }
177            
178            inline void exit_crit(PEGASUS_CRIT_TYPE *crit)
179            {
180 sage  1.2     pthread_mutex_unlock(&(crit->mut));
181 sage  1.1  }
182            
183            inline void destroy_crit(PEGASUS_CRIT_TYPE *crit)
184            {
185 sage  1.2     pthread_mutexattr_destroy(&(crit->mutatt));
186 sage  1.1  }
187            
188            inline static int pegasus_gettimeofday(struct timeval *tv)
189            {
190               return gettimeofday(tv,NULL);
191            }
192 sage  1.2  
193 sage  1.1  inline void exit_thread(PEGASUS_THREAD_RETURN rc)
194            {
195              pthread_exit(rc);
196            }
197            
198 sage  1.2  inline PEGASUS_THREAD_TYPE pegasus_thread_self(void)
199            {
200 sage  1.1     pthread_t pt = pthread_self();
201               return (* ((PEGASUS_THREAD_TYPE *) &pt));
202            }
203            
204 chuck 1.5  // l10n start
205            typedef pthread_key_t PEGASUS_THREAD_KEY_TYPE;
206            
207            inline Uint32 pegasus_key_create(PEGASUS_THREAD_KEY_TYPE * key)
208            {
209            	// Note: a destructor is not supported 
210            	// (because not supported on Windows (?))
211            	return pthread_key_create(key, NULL);
212            } 
213            
214            inline Uint32 pegasus_key_delete(PEGASUS_THREAD_KEY_TYPE key)
215            {
216 marek 1.6  	return 0;
217 chuck 1.5  } 
218            
219            inline void * pegasus_get_thread_specific(PEGASUS_THREAD_KEY_TYPE key)
220            {
221 marek 1.6  	return pthread_getspecific_d8_np(key);
222 chuck 1.5  } 
223            
224            inline Uint32 pegasus_set_thread_specific(PEGASUS_THREAD_KEY_TYPE key,
225            										 void * value)
226            {
227            	return pthread_setspecific(key, value);
228            } 
229            // l10n end
230            
231 sage  1.1  inline void destroy_thread(PEGASUS_THREAD_TYPE th, PEGASUS_THREAD_RETURN rc)
232            {
233               pthread_cancel(*(pthread_t *) &th);
234            
235            }
236            
237            
238            PEGASUS_NAMESPACE_END
239            
240            #endif // IPCzOSInclude

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2