comparison gcc/gthr-posix95.h @ 67:f6334be47118

update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
author nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
date Tue, 22 Mar 2011 17:18:12 +0900
parents 77e2b8dfacca
children
comparison
equal deleted inserted replaced
65:65488c3d617d 67:f6334be47118
1 /* Threads compatibility routines for libgcc2 and libobjc. */ 1 /* Threads compatibility routines for libgcc2 and libobjc. */
2 /* Compile this one with gcc. */ 2 /* Compile this one with gcc. */
3 /* Copyright (C) 2004, 2005, 2007, 2008, 2009 Free Software Foundation, Inc. 3 /* Copyright (C) 2004, 2005, 2007, 2008, 2009, 2010
4 Free Software Foundation, Inc.
4 5
5 This file is part of GCC. 6 This file is part of GCC.
6 7
7 GCC is free software; you can redistribute it and/or modify it under 8 GCC is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free 9 the terms of the GNU General Public License as published by the Free
182 183
183 /* Similar to Solaris, HP-UX 11 for PA-RISC provides stubs for pthread 184 /* Similar to Solaris, HP-UX 11 for PA-RISC provides stubs for pthread
184 calls in shared flavors of the HP-UX C library. Most of the stubs 185 calls in shared flavors of the HP-UX C library. Most of the stubs
185 have no functionality. The details are described in the "libc cumulative 186 have no functionality. The details are described in the "libc cumulative
186 patch" for each subversion of HP-UX 11. There are two special interfaces 187 patch" for each subversion of HP-UX 11. There are two special interfaces
187 provided for checking whether an application is linked to a pthread 188 provided for checking whether an application is linked to a shared pthread
188 library or not. However, these interfaces aren't available in early 189 library or not. However, these interfaces aren't available in early
189 libc versions. We also can't use pthread_once as some libc versions 190 pthread libraries. We also need a test that works for archive
190 call the init function. So, we use pthread_create to check whether it 191 libraries. We can't use pthread_once as some libc versions call the
191 is possible to create a thread or not. The stub implementation returns 192 init function. We also can't use pthread_create or pthread_attr_init
192 the error number ENOSYS. */ 193 as these create a thread and thereby prevent changing the default stack
194 size. The function pthread_default_stacksize_np is available in both
195 the archive and shared versions of libpthread. It can be used to
196 determine the default pthread stack size. There is a stub in some
197 shared libc versions which returns a zero size if pthreads are not
198 active. We provide an equivalent stub to handle cases where libc
199 doesn't provide one. */
193 200
194 #if defined(__hppa__) && defined(__hpux__) 201 #if defined(__hppa__) && defined(__hpux__)
195 202
196 #include <errno.h>
197
198 static volatile int __gthread_active = -1; 203 static volatile int __gthread_active = -1;
199
200 static void *
201 __gthread_start (void *arg __attribute__((unused)))
202 {
203 return NULL;
204 }
205
206 static void __gthread_active_init (void) __attribute__((noinline));
207 static void
208 __gthread_active_init (void)
209 {
210 static pthread_mutex_t __gthread_active_mutex = PTHREAD_MUTEX_INITIALIZER;
211 pthread_t t;
212 pthread_attr_t a;
213 int result;
214
215 __gthrw_(pthread_mutex_lock) (&__gthread_active_mutex);
216 if (__gthread_active < 0)
217 {
218 __gthrw_(pthread_attr_init) (&a);
219 __gthrw_(pthread_attr_setdetachstate) (&a, PTHREAD_CREATE_DETACHED);
220 result = __gthrw_(pthread_create) (&t, &a, __gthread_start, NULL);
221 if (result != ENOSYS)
222 __gthread_active = 1;
223 else
224 __gthread_active = 0;
225 __gthrw_(pthread_attr_destroy) (&a);
226 }
227 __gthrw_(pthread_mutex_unlock) (&__gthread_active_mutex);
228 }
229 204
230 static inline int 205 static inline int
231 __gthread_active_p (void) 206 __gthread_active_p (void)
232 { 207 {
233 /* Avoid reading __gthread_active twice on the main code path. */ 208 /* Avoid reading __gthread_active twice on the main code path. */
234 int __gthread_active_latest_value = __gthread_active; 209 int __gthread_active_latest_value = __gthread_active;
235 210 size_t __s;
236 /* This test is not protected to avoid taking a lock on the main code 211
237 path so every update of __gthread_active in a threaded program must
238 be atomic with regard to the result of the test. */
239 if (__builtin_expect (__gthread_active_latest_value < 0, 0)) 212 if (__builtin_expect (__gthread_active_latest_value < 0, 0))
240 { 213 {
241 __gthread_active_init (); 214 pthread_default_stacksize_np (0, &__s);
215 __gthread_active = __s ? 1 : 0;
242 __gthread_active_latest_value = __gthread_active; 216 __gthread_active_latest_value = __gthread_active;
243 } 217 }
244 218
245 return __gthread_active_latest_value != 0; 219 return __gthread_active_latest_value != 0;
246 } 220 }
319 pthread_t new_thread_handle; 293 pthread_t new_thread_handle;
320 294
321 if (!__gthread_active_p ()) 295 if (!__gthread_active_p ())
322 return NULL; 296 return NULL;
323 297
324 if (!(__gthrw_(pthread_create) (&new_thread_handle, NULL, (void *) func, arg))) 298 if (!(__gthrw_(pthread_create) (&new_thread_handle, &_objc_thread_attribs,
299 (void *) func, arg)))
325 thread_id = (objc_thread_t) new_thread_handle; 300 thread_id = (objc_thread_t) new_thread_handle;
326 else 301 else
327 thread_id = NULL; 302 thread_id = NULL;
328 303
329 return thread_id; 304 return thread_id;