1 mike 1.2 //%2006////////////////////////////////////////////////////////////////////////
2 //
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 // Copyright (c) 2005 Hewlett-Packard Development Company, L.P.; IBM Corp.;
10 // EMC Corporation; VERITAS Software Corporation; The Open Group.
11 // Copyright (c) 2006 Hewlett-Packard Development Company, L.P.; IBM Corp.;
12 // EMC Corporation; Symantec Corporation; The Open Group.
13 //
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 mike 1.2 // 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: Mike Brasher (m.brasher@inovadevelopment.com)
33 //
34 //%/////////////////////////////////////////////////////////////////////////////
35
|
110 mike 1.2
111 #endif
112 }
113
114 //==============================================================================
115 //
116 // Thread id TSD:
117 //
118 //==============================================================================
119
120 static Once _once = PEGASUS_ONCE_INITIALIZER;
121 static TSDKeyType _key;
122
123 static void _create_key()
124 {
125 TSDKey::create(&_key);
126 }
127
128 static inline void _set_id_tsd(Uint32 id)
129 {
130 once(&_once, _create_key);
131 mike 1.2 TSDKey::set_thread_specific(_key, (void*)(long)id);
132 }
133
134 static inline Uint32 _get_id_tsd()
135 {
136 once(&_once, _create_key);
137 void* ptr = TSDKey::get_thread_specific(_key);
138
139 if (!ptr)
140 {
141 // Main thread's id is 1!
142 return 1;
143 }
144
145 return (Uint32)(long)ptr;
146 }
147
148 //==============================================================================
149 //
150 // _get_stack_multiplier()
151 //
152 mike 1.2 //==============================================================================
153
154 static inline int _get_stack_multiplier()
155 {
156 #if defined(PEGASUS_OS_VMS)
157
158 static int _multiplier = 0;
159 static MutexType _multiplier_mutex = PEGASUS_MUTEX_INITIALIZER;
160
161 //
162 // This code uses a, 'hidden' (non-documented), VMS only, logical
163 // name (environment variable), PEGASUS_VMS_THREAD_STACK_MULTIPLIER,
164 // to allow in the field adjustment of the thread stack size.
165 //
166 // We only check for the logical name once to not have an
167 // impact on performance.
168 //
169 // Note: This code may have problems in a multithreaded environment
170 // with the setting of doneOnce to true.
171 //
172 // Current code in Cimserver and the clients do some serial thread
173 mike 1.2 // creations first so this is not a problem now.
174 //
175
176 if (_multiplier == 0)
177 {
178 mutex_lock(&_multiplier_mutex);
179
180 if (_multiplier == 0)
181 {
182 const char *env = getenv("PEGASUS_VMS_THREAD_STACK_MULTIPLIER");
183
184 if (env)
185 _multiplier = atoi(env);
186
187 if (_multiplier == 0)
188 _multiplier = 2;
189 }
190
191 mutex_unlock(&_multiplier_mutex);
192 }
193
194 mike 1.2 return _multiplier;
195 #else
196 return 2;
197 #endif
198 }
199
200 //==============================================================================
201 //
202 // PEGASUS_HAVE_PTHREADS
203 //
204 //==============================================================================
205
206 #if defined(PEGASUS_HAVE_PTHREADS)
207
208 int Threads::create(
209 ThreadType& thread,
210 Type type,
211 void* (*start)(void*),
212 void* arg)
213 {
214 // Initialize thread attributes:
215 mike 1.2
216 pthread_attr_t attr;
217 pthread_attr_init(&attr);
218
219 // Detached:
220
221 if (type == DETACHED)
222 {
223 #if defined(PEGASUS_PLATFORM_ZOS_ZSERIES_IBM)
224 int ds = 1;
225 pthread_attr_setdetachstate(&attr, &ds);
226 #else
227 pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
228 #endif
229 }
230
231 // Stack size:
232
233 #if defined(PEGASUS_PLATFORM_HPUX_PARISC_ACC) || defined(PEGASUS_OS_VMS)
234 {
235 size_t stacksize;
236 mike 1.2
237 if (pthread_attr_getstacksize(&attr, &stacksize) == 0)
238 {
239 int m = _get_stack_multiplier();
240 int rc = pthread_attr_setstacksize(&attr, stacksize * m);
241 PEGASUS_ASSERT(rc == 0);
242 }
243 }
244 #endif
245
246 // Scheduling policy:
247
248 #if defined(PEGASUS_PLATFORM_SOLARIS_SPARC_GNU) || \
249 defined(PEGASUS_PLATFORM_SOLARIS_SPARC_CC)
250 # if defined SUNOS_5_7
251 pthread_attr_setschedpolicy(&attr, SCHED_RR);
252 # else
253 pthread_attr_setschedpolicy(&attr, SCHED_OTHER);
254 # endif
255 #endif // PEGASUS_PLATFORM_SOLARIS_SPARC_GNU
256
257 mike 1.2 // Create thread:
258
|