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