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

  1 a.dunfey 1.12.16.1 //%2006////////////////////////////////////////////////////////////////////////
  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 a.dunfey 1.12.16.1 // 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 sage     1.2       // 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 a.dunfey 1.12.16.1 // 
 21 sage     1.2       // 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 sage     1.2       // 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: Markus Mueller (sedgewick_de@yahoo.de)
 33                    //
 34                    // Modified By: Mike Day (mdday@us.ibm.com)
 35 r.kieninger 1.12      //              Robert Kieninger, IBM (kieningr@de.ibm.com)
 36 sage        1.1       //
 37                       //%/////////////////////////////////////////////////////////////////////////////
 38                       
 39 sage        1.2       #ifndef IPC_ZOS_include
 40                       #define IPC_ZOS_include
 41 sage        1.1       
 42                       //#include <sched.h>
 43                       //#include <semaphore.h>
 44                       #include <pthread.h>
 45                       #include <signal.h>
 46                       #include <errno.h>
 47                       #include <sys/time.h>
 48                       #include <time.h>
 49                       //#include <sys/timex.h>
 50                       #include <unistd.h>
 51 r.kieninger 1.12      #include <stdio.h>
 52 sage        1.1       
 53                       #define SEM_VALUE_MAX 0xffffffff
 54                       
 55 r.kieninger 1.12      #define UNLOCKED_VALUE 0
 56                       #define LOCKED_VALUE 1
 57 sage        1.1       
 58                       PEGASUS_NAMESPACE_BEGIN
 59                       
 60                       //typedef sem_t PEGASUS_SEMAPHORE_TYPE;
 61                       //typedef pthread_t PEGASUS_THREAD_TYPE;
 62 sage        1.2       
 63 sage        1.1       typedef PEGASUS_UINT64 PEGASUS_THREAD_TYPE;
 64                       typedef pthread_mutex_t PEGASUS_MUTEX_TYPE;
 65                       
 66                       typedef struct {
 67                           Uint32 waiters;
 68                           pthread_mutex_t mutex;
 69                           pthread_cond_t cond;
 70                           PEGASUS_THREAD_TYPE owner;
 71                       } PEGASUS_SEM_HANDLE ;
 72                       
 73                       typedef struct {
 74                           pthread_mutex_t mut;
 75                           pthread_mutexattr_t mutatt;
 76                           PEGASUS_THREAD_TYPE owner;
 77                       } PEGASUS_MUTEX_HANDLE ;
 78                       
 79 r.kieninger 1.12      // !!!!!! needs to be changed to support spin_lock like behaviour
 80 sage        1.2       typedef PEGASUS_MUTEX_HANDLE PEGASUS_CRIT_TYPE;
 81 r.kieninger 1.12      //typedef cs_t PEGASUS_CRIT_TYPE;
 82                       #define PEGASUS_ATOMIC_INT_NATIVE
 83                       // define the _rep type for AtomicInt
 84                       typedef cs_t PEGASUS_ATOMIC_TYPE;
 85 sage        1.2       
 86 sage        1.1       struct _pthread_cleanup_buffer {
 87                           void (*__routine) (void *);             /* Function to call.  */
 88                           void *__arg;                            /* Its argument.  */
 89                           int __canceltype;                       /* Saved cancellation type. */
 90                           struct _pthread_cleanup_buffer *__prev;  /* Chaining of cleanup functions.*/
 91                       };
 92                       typedef struct _pthread_cleanup_buffer  PEGASUS_CLEANUP_HANDLE;
 93                       
 94 sage        1.2       //#define PEGASUS_THREAD_CDECL __cdecl
 95                       #define PEGASUS_THREAD_CDECL
 96                       
 97 sage        1.1       typedef void *PEGASUS_THREAD_RETURN;
 98                       
 99                       typedef struct {
100                           PEGASUS_THREAD_TYPE thid;
101                           pthread_attr_t thatt;
102                       } PEGASUS_THREAD_HANDLE ;
103                       
104                       //-----------------------------------------------------------------
105                       /// Conditionals to support native or generic Conditional Semaphore
106                       //-----------------------------------------------------------------
107                       
108 kumpf       1.8       #define PEGASUS_CONDITIONAL_NATIVE
109 sage        1.1       
110                       typedef pthread_cond_t PEGASUS_COND_TYPE;
111                       
112                       typedef struct {
113                           pthread_cond_t cond;
114                           PEGASUS_THREAD_TYPE owner;
115                       } PEGASUS_COND_HANDLE;
116                       
117                       //-----------------------------------------------------------------
118                       /// Conditionals to support native or generic atomic variables
119                       //-----------------------------------------------------------------
120                       
121                       
122                       //-----------------------------------------------------------------
123                       /// Conditionals to support native or generic read/write semaphores
124                       //-----------------------------------------------------------------
125                       
126 kumpf       1.8       #define PEGASUS_READWRITE_NATIVE
127 sage        1.1       
128 sage        1.2       typedef struct {
129                            pthread_rwlock_t rwlock;
130                            PEGASUS_THREAD_TYPE owner;
131                       } PEGASUS_RWLOCK_HANDLE;
132 sage        1.1       
133                       
134                       inline void pegasus_yield(void)
135                       {
136                             pthread_yield(NULL);
137                       }
138                       
139 sage        1.2       // pthreads cancellation calls
140 sage        1.1       inline void disable_cancel(void)
141                       {
142                          pthread_setintr(PTHREAD_INTR_DISABLE);
143                       }
144                       
145                       inline void enable_cancel(void)
146                       {
147                          pthread_setintr(PTHREAD_INTR_ENABLE);
148                       }
149                       
150                       inline void pegasus_sleep(int msec)
151                       {
152 marek       1.9       	int seconds;
153                       	int microsecs = msec * 1000; /* convert from milliseconds to microseconds */
154                       
155                       	if (microsecs < 1000000)
156                       	{
157                       		usleep(microsecs/2);
158                               pthread_testintr();
159                       		usleep(microsecs/2);
160                       
161                       	}
162                       	else
163                       	{
164                       		// sleep for loop seconds
165                       		seconds = microsecs / 1000000;
166                       		sleep(seconds);
167                       		// Usleep the remaining time
168                       		if ((seconds*1000000) < microsecs)
169                       		usleep(microsecs - (seconds*1000000));
170                       	}
171 sage        1.1       }
172                       
173                       inline void init_crit(PEGASUS_CRIT_TYPE *crit)
174                       {
175 sage        1.2          pthread_mutex_init(&(crit->mut), NULL);
176 sage        1.1       }
177                       
178                       inline void enter_crit(PEGASUS_CRIT_TYPE *crit)
179                       {
180 sage        1.2          pthread_mutex_lock(&(crit->mut));
181 sage        1.1       }
182                       
183                       inline void try_crit(PEGASUS_CRIT_TYPE *crit)
184                       {
185 sage        1.2          pthread_mutex_trylock(&(crit->mut));
186 sage        1.1       }
187                       
188                       inline void exit_crit(PEGASUS_CRIT_TYPE *crit)
189                       {
190 sage        1.2          pthread_mutex_unlock(&(crit->mut));
191 sage        1.1       }
192                       
193                       inline void destroy_crit(PEGASUS_CRIT_TYPE *crit)
194                       {
195 sage        1.2          pthread_mutexattr_destroy(&(crit->mutatt));
196 sage        1.1       }
197                       
198                       inline static int pegasus_gettimeofday(struct timeval *tv)
199                       {
200                          return gettimeofday(tv,NULL);
201                       }
202 sage        1.2       
203 sage        1.1       inline void exit_thread(PEGASUS_THREAD_RETURN rc)
204                       {
205                         pthread_exit(rc);
206                       }
207                       
208 sage        1.2       inline PEGASUS_THREAD_TYPE pegasus_thread_self(void)
209                       {
210 sage        1.1          pthread_t pt = pthread_self();
211                          return (* ((PEGASUS_THREAD_TYPE *) &pt));
212                       }
213                       
214 chuck       1.5       // l10n start
215                       typedef pthread_key_t PEGASUS_THREAD_KEY_TYPE;
216                       
217                       inline Uint32 pegasus_key_create(PEGASUS_THREAD_KEY_TYPE * key)
218                       {
219 r.kieninger 1.12      	// Note: a destructor is not supported
220 chuck       1.5       	// (because not supported on Windows (?))
221                       	return pthread_key_create(key, NULL);
222 r.kieninger 1.12      }
223 chuck       1.5       
224                       inline Uint32 pegasus_key_delete(PEGASUS_THREAD_KEY_TYPE key)
225                       {
226 marek       1.6       	return 0;
227 r.kieninger 1.12      }
228 chuck       1.5       
229                       inline void * pegasus_get_thread_specific(PEGASUS_THREAD_KEY_TYPE key)
230                       {
231 marek       1.6       	return pthread_getspecific_d8_np(key);
232 r.kieninger 1.12      }
233 chuck       1.5       
234                       inline Uint32 pegasus_set_thread_specific(PEGASUS_THREAD_KEY_TYPE key,
235                       										 void * value)
236                       {
237                       	return pthread_setspecific(key, value);
238 r.kieninger 1.12      }
239 chuck       1.5       // l10n end
240                       
241 sage        1.1       inline void destroy_thread(PEGASUS_THREAD_TYPE th, PEGASUS_THREAD_RETURN rc)
242                       {
243                          pthread_cancel(*(pthread_t *) &th);
244                       
245                       }
246                       
247                       PEGASUS_NAMESPACE_END
248                       
249                       #endif // IPCzOSInclude

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2