OLD | NEW |
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) 1997, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, | 3 /* Copyright (C) 1997, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, |
4 2008, 2009 Free Software Foundation, Inc. | 4 2008, 2009 Free Software Foundation, Inc. |
5 | 5 |
6 This file is part of GCC. | 6 This file is part of GCC. |
7 | 7 |
8 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 |
9 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 |
10 Software Foundation; either version 3, or (at your option) any later | 10 Software Foundation; either version 3, or (at your option) any later |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
44 typedef pthread_t __gthread_t; | 44 typedef pthread_t __gthread_t; |
45 typedef pthread_key_t __gthread_key_t; | 45 typedef pthread_key_t __gthread_key_t; |
46 typedef pthread_once_t __gthread_once_t; | 46 typedef pthread_once_t __gthread_once_t; |
47 typedef pthread_mutex_t __gthread_mutex_t; | 47 typedef pthread_mutex_t __gthread_mutex_t; |
48 typedef pthread_mutex_t __gthread_recursive_mutex_t; | 48 typedef pthread_mutex_t __gthread_recursive_mutex_t; |
49 typedef pthread_cond_t __gthread_cond_t; | 49 typedef pthread_cond_t __gthread_cond_t; |
50 typedef struct timespec __gthread_time_t; | 50 typedef struct timespec __gthread_time_t; |
51 | 51 |
52 /* POSIX like conditional variables are supported. Please look at comments | 52 /* POSIX like conditional variables are supported. Please look at comments |
53 in gthr.h for details. */ | 53 in gthr.h for details. */ |
54 #define __GTHREAD_HAS_COND» 1» | 54 #define __GTHREAD_HAS_COND» 1 |
55 | 55 |
56 #define __GTHREAD_MUTEX_INIT PTHREAD_MUTEX_INITIALIZER | 56 #define __GTHREAD_MUTEX_INIT PTHREAD_MUTEX_INITIALIZER |
57 #define __GTHREAD_ONCE_INIT PTHREAD_ONCE_INIT | 57 #define __GTHREAD_ONCE_INIT PTHREAD_ONCE_INIT |
58 #if defined(PTHREAD_RECURSIVE_MUTEX_INITIALIZER) | 58 #if defined(PTHREAD_RECURSIVE_MUTEX_INITIALIZER) |
59 #define __GTHREAD_RECURSIVE_MUTEX_INIT PTHREAD_RECURSIVE_MUTEX_INITIALIZER | 59 #define __GTHREAD_RECURSIVE_MUTEX_INIT PTHREAD_RECURSIVE_MUTEX_INITIALIZER |
60 #elif defined(PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP) | 60 #elif defined(PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP) |
61 #define __GTHREAD_RECURSIVE_MUTEX_INIT PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP | 61 #define __GTHREAD_RECURSIVE_MUTEX_INIT PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP |
62 #else | 62 #else |
63 #define __GTHREAD_RECURSIVE_MUTEX_INIT_FUNCTION __gthread_recursive_mutex_init_f
unction | 63 #define __GTHREAD_RECURSIVE_MUTEX_INIT_FUNCTION __gthread_recursive_mutex_init_f
unction |
64 #endif | 64 #endif |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
227 __gthread_active = 0; | 227 __gthread_active = 0; |
228 | 228 |
229 __gthread_active_latest_value = __gthread_active; | 229 __gthread_active_latest_value = __gthread_active; |
230 } | 230 } |
231 | 231 |
232 return __gthread_active_latest_value != 0; | 232 return __gthread_active_latest_value != 0; |
233 } | 233 } |
234 | 234 |
235 #else /* neither FreeBSD nor Solaris */ | 235 #else /* neither FreeBSD nor Solaris */ |
236 | 236 |
| 237 /* For a program to be multi-threaded the only thing that it certainly must |
| 238 be using is pthread_create. However, there may be other libraries that |
| 239 intercept pthread_create with their own definitions to wrap pthreads |
| 240 functionality for some purpose. In those cases, pthread_create being |
| 241 defined might not necessarily mean that libpthread is actually linked |
| 242 in. |
| 243 |
| 244 For the GNU C library, we can use a known internal name. This is always |
| 245 available in the ABI, but no other library would define it. That is |
| 246 ideal, since any public pthread function might be intercepted just as |
| 247 pthread_create might be. __pthread_key_create is an "internal" |
| 248 implementation symbol, but it is part of the public exported ABI. Also, |
| 249 it's among the symbols that the static libpthread.a always links in |
| 250 whenever pthread_create is used, so there is no danger of a false |
| 251 negative result in any statically-linked, multi-threaded program. |
| 252 |
| 253 For others, we choose pthread_cancel as a function that seems unlikely |
| 254 to be redefined by an interceptor library. The bionic (Android) C |
| 255 library does not provide pthread_cancel, so we do use pthread_create |
| 256 there (and interceptor libraries lose). */ |
| 257 |
| 258 #ifdef __GLIBC__ |
| 259 __gthrw2(__gthrw_(__pthread_key_create), |
| 260 __pthread_key_create, |
| 261 pthread_key_create) |
| 262 # define GTHR_ACTIVE_PROXY __gthrw_(__pthread_key_create) |
| 263 #elif defined (__BIONIC__) |
| 264 # define GTHR_ACTIVE_PROXY __gthrw_(pthread_create) |
| 265 #else |
| 266 # define GTHR_ACTIVE_PROXY __gthrw_(pthread_cancel) |
| 267 #endif |
| 268 |
237 static inline int | 269 static inline int |
238 __gthread_active_p (void) | 270 __gthread_active_p (void) |
239 { | 271 { |
240 static void *const __gthread_active_ptr | 272 static void *const __gthread_active_ptr |
241 = __extension__ (void *) &__gthrw_(pthread_cancel); | 273 = __extension__ (void *) >HR_ACTIVE_PROXY; |
242 return __gthread_active_ptr != 0; | 274 return __gthread_active_ptr != 0; |
243 } | 275 } |
244 | 276 |
245 #endif /* FreeBSD or Solaris */ | 277 #endif /* FreeBSD or Solaris */ |
246 | 278 |
247 #else /* not SUPPORTS_WEAK */ | 279 #else /* not SUPPORTS_WEAK */ |
248 | 280 |
249 /* Similar to Solaris, HP-UX 11 for PA-RISC provides stubs for pthread | 281 /* Similar to Solaris, HP-UX 11 for PA-RISC provides stubs for pthread |
250 calls in shared flavors of the HP-UX C library. Most of the stubs | 282 calls in shared flavors of the HP-UX C library. Most of the stubs |
251 have no functionality. The details are described in the "libc cumulative | 283 have no functionality. The details are described in the "libc cumulative |
(...skipping 634 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
886 | 918 |
887 static inline int | 919 static inline int |
888 __gthread_cond_destroy (__gthread_cond_t* __cond) | 920 __gthread_cond_destroy (__gthread_cond_t* __cond) |
889 { | 921 { |
890 return __gthrw_(pthread_cond_destroy) (__cond); | 922 return __gthrw_(pthread_cond_destroy) (__cond); |
891 } | 923 } |
892 | 924 |
893 #endif /* _LIBOBJC */ | 925 #endif /* _LIBOBJC */ |
894 | 926 |
895 #endif /* ! GCC_GTHR_POSIX_H */ | 927 #endif /* ! GCC_GTHR_POSIX_H */ |
OLD | NEW |