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

  1 karl  1.12 //%2006////////////////////////////////////////////////////////////////////////
  2 ramnath 1.1  //
  3 karl    1.8  // 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.6  // IBM Corp.; EMC Corporation, The Open Group.
  7 karl    1.8  // 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.9  // Copyright (c) 2005 Hewlett-Packard Development Company, L.P.; IBM Corp.;
 10              // EMC Corporation; VERITAS Software Corporation; The Open Group.
 11 karl    1.12 // Copyright (c) 2006 Hewlett-Packard Development Company, L.P.; IBM Corp.;
 12              // EMC Corporation; Symantec Corporation; The Open Group.
 13 ramnath 1.1  //
 14              // Permission is hereby granted, free of charge, to any person obtaining a copy
 15 kumpf   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 ramnath 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.2  // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
 22 ramnath 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.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 ramnath 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: Brian Bobryk (Brian.Bobryk@compaq.com)
 33              //
 34              // Modified By:
 35              //
 36              //%/////////////////////////////////////////////////////////////////////////////
 37              
 38              #ifndef IPC_TRU64_include
 39              #define IPC_TRU64_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 ramnath 1.1  
 49              PEGASUS_NAMESPACE_BEGIN
 50              
 51              typedef sem_t PEGASUS_SEMAPHORE_TYPE;
 52              typedef pthread_t PEGASUS_THREAD_TYPE;
 53              typedef pthread_mutex_t PEGASUS_MUTEX_TYPE;
 54              
 55              typedef struct {
 56 ramnath 1.3  	PEGASUS_SEMAPHORE_TYPE sem;
 57              	PEGASUS_THREAD_TYPE owner;
 58              } PEGASUS_SEM_HANDLE ;
 59              
 60              /*
 61              typedef struct {
 62 ramnath 1.1      Uint32 waiters;
 63                  pthread_mutex_t mutex;
 64                  pthread_cond_t cond;
 65                  PEGASUS_THREAD_TYPE owner;
 66              } PEGASUS_SEM_HANDLE ;
 67 ramnath 1.3  */
 68 ramnath 1.1  
 69              typedef struct {
 70                  pthread_mutex_t mut;
 71                  pthread_mutexattr_t mutatt;
 72                  pthread_t owner;
 73              } PEGASUS_MUTEX_HANDLE ;
 74              
 75              typedef PEGASUS_MUTEX_HANDLE PEGASUS_CRIT_TYPE;
 76              
 77              typedef void *PEGASUS_CLEANUP_HANDLE ;
 78              typedef void *PEGASUS_THREAD_RETURN;
 79              
 80              #define PEGASUS_THREAD_CDECL
 81              
 82              typedef struct {
 83                  pthread_t thid;
 84                  pthread_attr_t thatt;
 85              } PEGASUS_THREAD_HANDLE ;
 86              
 87              //-----------------------------------------------------------------
 88              /// Conditionals to support native or generic Conditional Semaphore
 89 ramnath 1.1  //-----------------------------------------------------------------
 90              
 91 kumpf   1.7  #define PEGASUS_CONDITIONAL_NATIVE
 92 ramnath 1.1  
 93              typedef pthread_cond_t PEGASUS_COND_TYPE;
 94              
 95              typedef struct {
 96                  pthread_cond_t cond;
 97                  pthread_t owner;
 98              } PEGASUS_COND_HANDLE;
 99              
100              
101              //-----------------------------------------------------------------
102              /// Conditionals to support native or generic atomic variables
103              //-----------------------------------------------------------------
104              
105 kumpf   1.7  // #define PEGASUS_ATOMIC_INT_NATIVE
106 ramnath 1.1  
107              
108              //-----------------------------------------------------------------
109              /// Conditionals to support native or generic read/write semaphores
110              //-----------------------------------------------------------------
111              
112 kumpf   1.7  #define PEGASUS_READWRITE_NATIVE
113 ramnath 1.1  
114              typedef struct {
115                  pthread_rwlock_t rwlock;
116                  pthread_t owner;
117              } PEGASUS_RWLOCK_HANDLE;
118              
119              inline void pegasus_yield(void)
120              {
121                    sched_yield();
122              }
123              
124              
125              // pthreads cancellation calls 
126              inline void disable_cancel(void)
127              {
128 kumpf   1.11    pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, NULL);
129 ramnath 1.1  }
130              
131              inline void enable_cancel(void)
132              {
133 kumpf   1.11    pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL);
134 ramnath 1.1  }
135              
136              inline void pegasus_sleep(int msec)
137              {
138                  struct timespec wait;
139                  wait.tv_sec = msec / 1000;
140 kumpf   1.4      wait.tv_nsec = (msec % 1000) * 1000000;
141 ramnath 1.1      nanosleep(&wait, NULL);
142              }
143              
144              inline void init_crit(PEGASUS_CRIT_TYPE *crit)
145              {
146                 pthread_mutex_init(&(crit->mut), NULL);
147              }
148              
149              inline void enter_crit(PEGASUS_CRIT_TYPE *crit)
150              {
151                 pthread_mutex_lock(&(crit->mut));
152              }
153              
154              inline void try_crit(PEGASUS_CRIT_TYPE *crit)
155              {
156                 pthread_mutex_trylock(&(crit->mut));
157              }
158              
159              inline void exit_crit(PEGASUS_CRIT_TYPE *crit)
160              {
161                 pthread_mutex_unlock(&(crit->mut));
162 ramnath 1.1  }
163              
164              inline void destroy_crit(PEGASUS_CRIT_TYPE *crit)
165              {
166                 pthread_mutexattr_destroy(&(crit->mutatt));
167              }
168              
169              static inline int pegasus_gettimeofday(struct timeval *tv) { return(gettimeofday(tv, NULL)); }
170              
171              inline void exit_thread(PEGASUS_THREAD_RETURN rc)
172              {
173                pthread_exit(rc);
174              }
175              
176              inline PEGASUS_THREAD_TYPE pegasus_thread_self(void) 
177              { 
178                 return(pthread_self());
179              }
180              
181 chuck   1.5  // l10n start
182              typedef pthread_key_t PEGASUS_THREAD_KEY_TYPE;
183              
184              inline Uint32 pegasus_key_create(PEGASUS_THREAD_KEY_TYPE * key)
185              {
186              	// Note: a destructor is not supported 
187              	// (because not supported on Windows (?))
188              	return pthread_key_create(key, NULL);
189              } 
190              
191              inline Uint32 pegasus_key_delete(PEGASUS_THREAD_KEY_TYPE key)
192              {
193              	return pthread_key_delete(key);
194              } 
195              
196              inline void * pegasus_get_thread_specific(PEGASUS_THREAD_KEY_TYPE key)
197              {
198              	return pthread_getspecific(key);
199              } 
200              
201              inline Uint32 pegasus_set_thread_specific(PEGASUS_THREAD_KEY_TYPE key,
202 chuck   1.5  										 void * value)
203              {
204              	return pthread_setspecific(key, value);
205              } 
206              // l10n end
207              
208 ramnath 1.1  inline void destroy_thread(PEGASUS_THREAD_TYPE th, PEGASUS_THREAD_RETURN rc)
209              {
210                 pthread_cancel(th);
211              }
212              
213              
214              PEGASUS_NAMESPACE_END
215              
216              #endif // IPCTRU64Include

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2