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

  1 carson.hovey 1.2 //%2005////////////////////////////////////////////////////////////////////////
  2 gs.keenan    1.1 //
  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.
  7                  // Copyright (c) 2004 BMC Software; Hewlett-Packard Development Company, L.P.;
  8                  // IBM Corp.; EMC Corporation; VERITAS Software Corporation; The Open Group.
  9 carson.hovey 1.2 // Copyright (c) 2005 Hewlett-Packard Development Company, L.P.; IBM Corp.;
 10                  // EMC Corporation; VERITAS Software Corporation; The Open Group.
 11 gs.keenan    1.1 //
 12                  // Permission is hereby granted, free of charge, to any person obtaining a copy
 13                  // 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                  // 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                  // 
 19                  // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
 20                  // 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                  // 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                  // 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 gs.keenan    1.1 // Modified By: Sean Keenan (sean.keenan@hp.com)
 33                  //
 34                  //%/////////////////////////////////////////////////////////////////////////////
 35                  
 36                  #ifndef IPC_VMS_include
 37                  #define IPC_VMS_include
 38                  
 39                  #include <pthread.h>
 40                  #include <signal.h>
 41                  #include <errno.h>
 42                  #include <sys/time.h>
 43                  #include <time.h>
 44                  
 45                  PEGASUS_NAMESPACE_BEGIN
 46                  
 47                  int timeval_subtract (struct timeval *result, 
 48                  		      struct timeval *x, 
 49                  		      struct timeval *y);
 50                  
 51                  
 52                  typedef pthread_t PEGASUS_THREAD_TYPE;
 53 gs.keenan    1.1 typedef pthread_mutex_t PEGASUS_MUTEX_TYPE;
 54                  
 55                  typedef struct {
 56                      Uint32 waiters;
 57                      pthread_mutex_t mutex;
 58                      pthread_cond_t cond;
 59                      pthread_t owner;
 60                  } PEGASUS_SEM_HANDLE ;
 61                  
 62                  typedef struct {
 63                      pthread_mutex_t mut;
 64                      pthread_mutexattr_t mutatt;
 65                      pthread_t owner;
 66                  } PEGASUS_MUTEX_HANDLE ;
 67                  
 68                  typedef void *PEGASUS_CLEANUP_HANDLE;
 69                  typedef void *PEGASUS_THREAD_RETURN;
 70                  
 71                  #define PEGASUS_THREAD_CDECL
 72                  
 73                  typedef struct {
 74 gs.keenan    1.1     pthread_t thid;
 75                      pthread_attr_t thatt;
 76                  } PEGASUS_THREAD_HANDLE ;
 77                  
 78                  //-----------------------------------------------------------------
 79                  /// Conditionals to support native or generic Conditional Semaphore
 80                  //-----------------------------------------------------------------
 81                  
 82                  #define PEGASUS_CONDITIONAL_NATIVE = 1
 83                  
 84                  typedef pthread_cond_t PEGASUS_COND_TYPE;
 85                  
 86                  typedef struct {
 87                      pthread_cond_t cond;
 88                      pthread_t owner;
 89                  } PEGASUS_COND_HANDLE;
 90                  
 91                  
 92                  //-----------------------------------------------------------------
 93                  /// Conditionals to support native or generic read/write semaphores
 94                  //-----------------------------------------------------------------
 95 gs.keenan    1.1 
 96                  
 97                  //-----------------------------------------------------------------
 98                  // NOTE: Tue Oct  9 13:36:53 2001 mdday
 99                  //
100                  //  I put some read/write counting into the Thread test program to see
101                  //  how native r/w performance compares to generic r/w on linux. 
102                  //  For RH linux 7.1, the generic r/w lock in IPC.cpp performs 
103                  //  much better than the pthreads native implementation.
104                  //  
105                  //  Here are the data (remember that there are 4 readers for every one
106                  //  writer):
107                  // 
108                  //  Generic  read operations  6538     <- 4:1 ratio of reads to writes
109                  //           write operations 1422
110                  //
111                  //  Native   read operations   2060    <- 1:1 even though there are 
112                  //           write operations  2033       4 readers for every writer
113                  //
114                  //
115                  //  Comments -
116 gs.keenan    1.1 // 
117                  // The native implementation prefers writers, which slows the entire
118                  // test down because write operations take longer than read operations.
119                  // Moreover, as soon as one writer gains the lock, the next owner will 
120                  // always be a writer until there are no further writers. Readers are 
121                  // blocked out until all writers are sleeping. 
122                  //
123                  // In the test there are 4 readers for every writer. However, the 
124                  // native r/w lock severely skews resources toward writers.
125                  // 
126                  // The generic implementation has no preference among readers and writers. 
127                  // Therefore whichever thread is ready to read or write will gain the lock
128                  // with no dependence on whether the predecessor is a reader or writer. 
129                  // This results in higher throughput in the test program for linux.
130                  //
131                  // I would encourage all the platform maintainers to run their own tests
132                  // so we can decide which implementation to use for production builds. 
133                  //
134                  //-----------------------------------------------------------------
135                  
136                  
137 gs.keenan    1.1 inline void pegasus_yield(void)
138                  {
139                        sched_yield();
140                  }
141                  
142                  // pthreads cancellation calls 
143                  inline void disable_cancel(void)
144                  {
145 kumpf        1.3    pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, NULL);
146 gs.keenan    1.1 }
147                  
148                  inline void enable_cancel(void)
149                  {
150 kumpf        1.3    pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL);
151 gs.keenan    1.1 }
152                  
153                  inline void pegasus_sleep(int msec)
154                  {
155                     sleep(msec/1000);
156                  }
157                  
158                  inline static int pegasus_gettimeofday(struct timeval *tv)
159                  {
160                     return(gettimeofday(tv, NULL));
161                  }
162                     
163                  inline void exit_thread(PEGASUS_THREAD_RETURN rc)
164                  {
165                    pthread_exit(rc);
166                  }
167                  
168                  inline PEGASUS_THREAD_TYPE pegasus_thread_self(void) 
169                  { 
170                     return(pthread_self());
171                  }
172 gs.keenan    1.1 
173                  // l10n start
174                  typedef pthread_key_t PEGASUS_THREAD_KEY_TYPE;
175                  
176                  inline Uint32 pegasus_key_create(PEGASUS_THREAD_KEY_TYPE * key)
177                  {
178                  	// Note: a destructor is not supported 
179                  	// (because not supported on Windows (?))
180                  	return pthread_key_create(key, NULL);
181                  } 
182                  
183                  inline Uint32 pegasus_key_delete(PEGASUS_THREAD_KEY_TYPE key)
184                  {
185                  	return pthread_key_delete(key);
186                  } 
187                  
188                  inline void * pegasus_get_thread_specific(PEGASUS_THREAD_KEY_TYPE key)
189                  {
190                  	return pthread_getspecific(key);
191                  } 
192                  
193 gs.keenan    1.1 inline Uint32 pegasus_set_thread_specific(PEGASUS_THREAD_KEY_TYPE key,
194                  					  void * value)
195                  {
196                  	return pthread_setspecific(key, value);
197                  } 
198                  // l10n end
199                  
200                  
201                  inline void destroy_thread(PEGASUS_THREAD_TYPE th, PEGASUS_THREAD_RETURN rc)
202                  {
203                     pthread_cancel(th);
204                  }
205                  
206                  PEGASUS_NAMESPACE_END
207                  
208                  #endif // IPCVMS_Include

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2