Back to index

glibc  2.9
internals.h
Go to the documentation of this file.
00001 /* Linuxthreads - a simple clone()-based implementation of Posix        */
00002 /* threads for Linux.                                                   */
00003 /* Copyright (C) 1996 Xavier Leroy (Xavier.Leroy@inria.fr)              */
00004 /*                                                                      */
00005 /* This program is free software; you can redistribute it and/or        */
00006 /* modify it under the terms of the GNU Library General Public License  */
00007 /* as published by the Free Software Foundation; either version 2       */
00008 /* of the License, or (at your option) any later version.               */
00009 /*                                                                      */
00010 /* This program is distributed in the hope that it will be useful,      */
00011 /* but WITHOUT ANY WARRANTY; without even the implied warranty of       */
00012 /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        */
00013 /* GNU Library General Public License for more details.                 */
00014 
00015 #ifndef _INTERNALS_H
00016 #define _INTERNALS_H 1
00017 
00018 /* Internal data structures */
00019 
00020 /* Includes */
00021 
00022 #include <limits.h>
00023 #include <signal.h>
00024 #include <stdbool.h>
00025 #include <unistd.h>
00026 #include <stackinfo.h>
00027 #include <sigcontextinfo.h>
00028 
00029 #include <tls.h>
00030 #include "descr.h"
00031 
00032 #include "semaphore.h"
00033 #include <pthread-functions.h>
00034 
00035 #ifndef THREAD_GETMEM
00036 # define THREAD_GETMEM(descr, member) descr->member
00037 #endif
00038 #ifndef THREAD_GETMEM_NC
00039 # define THREAD_GETMEM_NC(descr, member) descr->member
00040 #endif
00041 #ifndef THREAD_SETMEM
00042 # define THREAD_SETMEM(descr, member, value) descr->member = (value)
00043 #endif
00044 #ifndef THREAD_SETMEM_NC
00045 # define THREAD_SETMEM_NC(descr, member, value) descr->member = (value)
00046 #endif
00047 
00048 #if !defined NOT_IN_libc && defined FLOATING_STACKS
00049 # define LIBC_THREAD_GETMEM(descr, member) THREAD_GETMEM (descr, member)
00050 # define LIBC_THREAD_SETMEM(descr, member, value) \
00051   THREAD_SETMEM (descr, member, value)
00052 #else
00053 # define LIBC_THREAD_GETMEM(descr, member) descr->member
00054 # define LIBC_THREAD_SETMEM(descr, member, value) descr->member = (value)
00055 #endif
00056 
00057 typedef void (*destr_function)(void *);
00058 
00059 struct pthread_key_struct {
00060   int in_use;                   /* already allocated? */
00061   destr_function destr;         /* destruction routine */
00062 };
00063 
00064 
00065 #define PTHREAD_START_ARGS_INITIALIZER(fct) \
00066   { (void *(*) (void *)) fct, NULL, {{0, }}, 0, { 0 } }
00067 
00068 
00069 /* The type of thread handles. */
00070 
00071 typedef struct pthread_handle_struct * pthread_handle;
00072 
00073 struct pthread_handle_struct {
00074   struct _pthread_fastlock h_lock; /* Fast lock for sychronized access */
00075   pthread_descr h_descr;        /* Thread descriptor or NULL if invalid */
00076   char * h_bottom;              /* Lowest address in the stack thread */
00077 };
00078 
00079 /* The type of messages sent to the thread manager thread */
00080 
00081 struct pthread_request {
00082   pthread_descr req_thread;     /* Thread doing the request */
00083   enum {                        /* Request kind */
00084     REQ_CREATE, REQ_FREE, REQ_PROCESS_EXIT, REQ_MAIN_THREAD_EXIT,
00085     REQ_POST, REQ_DEBUG, REQ_KICK, REQ_FOR_EACH_THREAD
00086   } req_kind;
00087   union {                       /* Arguments for request */
00088     struct {                    /* For REQ_CREATE: */
00089       const pthread_attr_t * attr; /* thread attributes */
00090       void * (*fn)(void *);     /*   start function */
00091       void * arg;               /*   argument to start function */
00092       sigset_t mask;            /*   signal mask */
00093     } create;
00094     struct {                    /* For REQ_FREE: */
00095       pthread_t thread_id;      /*   identifier of thread to free */
00096     } free;
00097     struct {                    /* For REQ_PROCESS_EXIT: */
00098       int code;                 /*   exit status */
00099     } exit;
00100     void * post;                /* For REQ_POST: the semaphore */
00101     struct {                /* For REQ_FOR_EACH_THREAD: callback */
00102       void (*fn)(void *, pthread_descr);
00103       void *arg;
00104     } for_each;
00105   } req_args;
00106 };
00107 
00108 
00109 
00110 typedef void (*arch_sighandler_t) (int, SIGCONTEXT);
00111 union sighandler
00112 {
00113   arch_sighandler_t old;
00114   void (*rt) (int, struct siginfo *, struct ucontext *);
00115 };
00116 extern union sighandler __sighandler[NSIG];
00117 
00118 
00119 /* Signals used for suspend/restart and for cancellation notification.  */
00120 
00121 extern int __pthread_sig_restart;
00122 extern int __pthread_sig_cancel;
00123 
00124 /* Signal used for interfacing with gdb */
00125 
00126 extern int __pthread_sig_debug;
00127 
00128 /* Global array of thread handles, used for validating a thread id
00129    and retrieving the corresponding thread descriptor. Also used for
00130    mapping the available stack segments. */
00131 
00132 extern struct pthread_handle_struct __pthread_handles[PTHREAD_THREADS_MAX];
00133 
00134 /* Descriptor of the main thread */
00135 
00136 extern pthread_descr __pthread_main_thread;
00137 
00138 /* File descriptor for sending requests to the thread manager.
00139    Initially -1, meaning that __pthread_initialize_manager must be called. */
00140 
00141 extern int __pthread_manager_request;
00142 
00143 /* Other end of the pipe for sending requests to the thread manager. */
00144 
00145 extern int __pthread_manager_reader;
00146 
00147 #ifdef FLOATING_STACKS
00148 /* Maximum stack size.  */
00149 extern size_t __pthread_max_stacksize;
00150 #endif
00151 
00152 /* Pending request for a process-wide exit */
00153 
00154 extern int __pthread_exit_requested, __pthread_exit_code;
00155 
00156 /* Set to 1 by gdb if we're debugging */
00157 
00158 extern volatile int __pthread_threads_debug;
00159 
00160 /* Globally enabled events.  */
00161 extern volatile td_thr_events_t __pthread_threads_events;
00162 
00163 /* Pointer to descriptor of thread with last event.  */
00164 extern volatile pthread_descr __pthread_last_event;
00165 
00166 /* Flag which tells whether we are executing on SMP kernel. */
00167 extern int __pthread_smp_kernel;
00168 
00169 /* Return the handle corresponding to a thread id */
00170 
00171 static inline pthread_handle thread_handle(pthread_t id)
00172 {
00173   return &__pthread_handles[id % PTHREAD_THREADS_MAX];
00174 }
00175 
00176 /* Validate a thread handle. Must have acquired h->h_spinlock before. */
00177 
00178 static inline int invalid_handle(pthread_handle h, pthread_t id)
00179 {
00180   return h->h_descr == NULL || h->h_descr->p_tid != id || h->h_descr->p_terminated;
00181 }
00182 
00183 static inline int nonexisting_handle(pthread_handle h, pthread_t id)
00184 {
00185   return h->h_descr == NULL || h->h_descr->p_tid != id;
00186 }
00187 
00188 /* Fill in defaults left unspecified by pt-machine.h.  */
00189 
00190 /* We round up a value with page size. */
00191 #ifndef page_roundup
00192 #define page_roundup(v,p) ((((size_t) (v)) + (p) - 1) & ~((p) - 1))
00193 #endif
00194 
00195 /* The page size we can get from the system.  This should likely not be
00196    changed by the machine file but, you never know.  */
00197 #ifndef PAGE_SIZE
00198 #define PAGE_SIZE  (sysconf (_SC_PAGE_SIZE))
00199 #endif
00200 
00201 /* The initial size of the thread stack.  Must be a multiple of PAGE_SIZE.  */
00202 #ifndef INITIAL_STACK_SIZE
00203 #define INITIAL_STACK_SIZE  (4 * PAGE_SIZE)
00204 #endif
00205 
00206 /* Size of the thread manager stack. The "- 32" avoids wasting space
00207    with some malloc() implementations. */
00208 #ifndef THREAD_MANAGER_STACK_SIZE
00209 #define THREAD_MANAGER_STACK_SIZE  (2 * PAGE_SIZE - 32)
00210 #endif
00211 
00212 /* The base of the "array" of thread stacks.  The array will grow down from
00213    here.  Defaults to the calculated bottom of the initial application
00214    stack.  */
00215 #ifndef THREAD_STACK_START_ADDRESS
00216 #define THREAD_STACK_START_ADDRESS  __pthread_initial_thread_bos
00217 #endif
00218 
00219 /* If MEMORY_BARRIER isn't defined in pt-machine.h, assume the
00220    architecture doesn't need a memory barrier instruction (e.g. Intel
00221    x86).  Still we need the compiler to respect the barrier and emit
00222    all outstanding operations which modify memory.  Some architectures
00223    distinguish between full, read and write barriers.  */
00224 
00225 #ifndef MEMORY_BARRIER
00226 #define MEMORY_BARRIER() asm ("" : : : "memory")
00227 #endif
00228 #ifndef READ_MEMORY_BARRIER
00229 #define READ_MEMORY_BARRIER() MEMORY_BARRIER()
00230 #endif
00231 #ifndef WRITE_MEMORY_BARRIER
00232 #define WRITE_MEMORY_BARRIER() MEMORY_BARRIER()
00233 #endif
00234 
00235 /* Max number of times we must spin on a spinlock calling sched_yield().
00236    After MAX_SPIN_COUNT iterations, we put the calling thread to sleep. */
00237 
00238 #ifndef MAX_SPIN_COUNT
00239 #define MAX_SPIN_COUNT 50
00240 #endif
00241 
00242 /* Max number of times the spinlock in the adaptive mutex implementation
00243    spins actively on SMP systems.  */
00244 
00245 #ifndef MAX_ADAPTIVE_SPIN_COUNT
00246 #define MAX_ADAPTIVE_SPIN_COUNT 100
00247 #endif
00248 
00249 /* Duration of sleep (in nanoseconds) when we can't acquire a spinlock
00250    after MAX_SPIN_COUNT iterations of sched_yield().
00251    With the 2.0 and 2.1 kernels, this MUST BE > 2ms.
00252    (Otherwise the kernel does busy-waiting for realtime threads,
00253     giving other threads no chance to run.) */
00254 
00255 #ifndef SPIN_SLEEP_DURATION
00256 #define SPIN_SLEEP_DURATION 2000001
00257 #endif
00258 
00259 /* Defined and used in libc.so.  */
00260 extern int __libc_multiple_threads attribute_hidden;
00261 extern int __librt_multiple_threads;
00262 
00263 /* Debugging */
00264 
00265 #ifdef DEBUG
00266 #include <assert.h>
00267 #define ASSERT assert
00268 #define MSG __pthread_message
00269 #else
00270 #define ASSERT(x)
00271 #define MSG(msg,arg...)
00272 #endif
00273 
00274 /* Internal global functions */
00275 
00276 extern void __pthread_do_exit (void *retval, char *currentframe)
00277      __attribute__ ((__noreturn__));
00278 extern void __pthread_destroy_specifics (void);
00279 extern void __pthread_perform_cleanup (char *currentframe);
00280 extern void __pthread_init_max_stacksize (void);
00281 extern int __pthread_initialize_manager (void);
00282 extern void __pthread_message (const char * fmt, ...);
00283 extern int __pthread_manager (void *reqfd);
00284 extern int __pthread_manager_event (void *reqfd);
00285 extern void __pthread_manager_sighandler (int sig);
00286 extern void __pthread_reset_main_thread (void);
00287 extern void __pthread_once_fork_prepare (void);
00288 extern void __pthread_once_fork_parent (void);
00289 extern void __pthread_once_fork_child (void);
00290 extern void __flockfilelist (void);
00291 extern void __funlockfilelist (void);
00292 extern void __fresetlockfiles (void);
00293 extern void __pthread_manager_adjust_prio (int thread_prio);
00294 extern void __pthread_initialize_minimal (void);
00295 
00296 extern int __pthread_attr_setguardsize (pthread_attr_t *__attr,
00297                                    size_t __guardsize);
00298 extern int __pthread_attr_getguardsize (const pthread_attr_t *__attr,
00299                                    size_t *__guardsize);
00300 extern int __pthread_attr_setstackaddr (pthread_attr_t *__attr,
00301                                    void *__stackaddr);
00302 extern int __pthread_attr_getstackaddr (const pthread_attr_t *__attr,
00303                                    void **__stackaddr);
00304 extern int __pthread_attr_setstacksize (pthread_attr_t *__attr,
00305                                    size_t __stacksize);
00306 extern int __pthread_attr_getstacksize (const pthread_attr_t *__attr,
00307                                    size_t *__stacksize);
00308 extern int __pthread_attr_setstack (pthread_attr_t *__attr, void *__stackaddr,
00309                                 size_t __stacksize);
00310 extern int __pthread_attr_getstack (const pthread_attr_t *__attr, void **__stackaddr,
00311                                 size_t *__stacksize);
00312 extern int __pthread_attr_destroy (pthread_attr_t *attr);
00313 extern int __pthread_attr_setdetachstate (pthread_attr_t *attr,
00314                                      int detachstate);
00315 extern int __pthread_attr_getdetachstate (const pthread_attr_t *attr,
00316                                      int *detachstate);
00317 extern int __pthread_attr_setschedparam (pthread_attr_t *attr,
00318                                     const struct sched_param *param);
00319 extern int __pthread_attr_getschedparam (const pthread_attr_t *attr,
00320                                     struct sched_param *param);
00321 extern int __pthread_attr_setschedpolicy (pthread_attr_t *attr, int policy);
00322 extern int __pthread_attr_getschedpolicy (const pthread_attr_t *attr,
00323                                      int *policy);
00324 extern int __pthread_attr_setinheritsched (pthread_attr_t *attr, int inherit);
00325 extern int __pthread_attr_getinheritsched (const pthread_attr_t *attr,
00326                                       int *inherit);
00327 extern int __pthread_attr_setscope (pthread_attr_t *attr, int scope);
00328 extern int __pthread_attr_getscope (const pthread_attr_t *attr, int *scope);
00329 
00330 extern int __pthread_getconcurrency (void);
00331 extern int __pthread_setconcurrency (int __level);
00332 extern int __pthread_mutex_timedlock (pthread_mutex_t *__mutex,
00333                                   const struct timespec *__abstime);
00334 extern int __pthread_mutexattr_getpshared (const pthread_mutexattr_t *__attr,
00335                                       int *__pshared);
00336 extern int __pthread_mutexattr_setpshared (pthread_mutexattr_t *__attr,
00337                                       int __pshared);
00338 extern int __pthread_mutexattr_gettype (const pthread_mutexattr_t *__attr,
00339                                    int *__kind);
00340 extern void __pthread_kill_other_threads_np (void);
00341 extern int __pthread_mutex_init (pthread_mutex_t *__mutex,
00342                              __const pthread_mutexattr_t *__mutex_attr);
00343 extern int __pthread_mutex_destroy (pthread_mutex_t *__mutex);
00344 extern int __pthread_mutex_lock (pthread_mutex_t *__mutex);
00345 extern int __pthread_mutex_trylock (pthread_mutex_t *__mutex);
00346 extern int __pthread_mutex_unlock (pthread_mutex_t *__mutex);
00347 #if defined NOT_IN_libc && defined IS_IN_libpthread
00348 hidden_proto (__pthread_mutex_init)
00349 hidden_proto (__pthread_mutex_destroy)
00350 hidden_proto (__pthread_mutex_lock)
00351 hidden_proto (__pthread_mutex_trylock)
00352 hidden_proto (__pthread_mutex_unlock)
00353 #endif
00354 extern int __pthread_cond_init (pthread_cond_t *cond,
00355                             const pthread_condattr_t *cond_attr);
00356 extern int __pthread_cond_destroy (pthread_cond_t *cond);
00357 extern int __pthread_cond_wait (pthread_cond_t *cond, pthread_mutex_t *mutex);
00358 extern int __pthread_cond_timedwait (pthread_cond_t *cond,
00359                                  pthread_mutex_t *mutex,
00360                                  const struct timespec *abstime);
00361 extern int __pthread_cond_signal (pthread_cond_t *cond);
00362 extern int __pthread_cond_broadcast (pthread_cond_t *cond);
00363 extern int __pthread_condattr_init (pthread_condattr_t *attr);
00364 extern int __pthread_condattr_destroy (pthread_condattr_t *attr);
00365 extern pthread_t __pthread_self (void);
00366 extern pthread_descr __pthread_thread_self (void);
00367 extern pthread_descr __pthread_self_stack (void) attribute_hidden;
00368 extern int __pthread_equal (pthread_t thread1, pthread_t thread2);
00369 extern void __pthread_exit (void *retval);
00370 extern int __pthread_getschedparam (pthread_t thread, int *policy,
00371                                 struct sched_param *param);
00372 extern int __pthread_setschedparam (pthread_t thread, int policy,
00373                                 const struct sched_param *param);
00374 extern int __pthread_setcancelstate (int state, int * oldstate);
00375 extern int __pthread_setcanceltype (int type, int * oldtype);
00376 
00377 extern void __pthread_restart_old(pthread_descr th);
00378 extern void __pthread_suspend_old(pthread_descr self);
00379 extern int __pthread_timedsuspend_old(pthread_descr self, const struct timespec *abs);
00380 
00381 extern void __pthread_restart_new(pthread_descr th);
00382 extern void __pthread_suspend_new(pthread_descr self);
00383 extern int __pthread_timedsuspend_new(pthread_descr self, const struct timespec *abs);
00384 
00385 extern void __pthread_wait_for_restart_signal(pthread_descr self);
00386 
00387 extern void __pthread_sigsuspend (const sigset_t *mask) attribute_hidden;
00388 
00389 extern int __pthread_yield (void);
00390 
00391 extern int __pthread_rwlock_timedrdlock (pthread_rwlock_t *__restrict __rwlock,
00392                                     __const struct timespec *__restrict
00393                                     __abstime);
00394 extern int __pthread_rwlock_timedwrlock (pthread_rwlock_t *__restrict __rwlock,
00395                                     __const struct timespec *__restrict
00396                                     __abstime);
00397 extern int __pthread_rwlockattr_destroy (pthread_rwlockattr_t *__attr);
00398 
00399 extern int __pthread_barrierattr_getpshared (__const pthread_barrierattr_t *
00400                                         __restrict __attr,
00401                                         int *__restrict __pshared);
00402 
00403 extern int __pthread_spin_lock (pthread_spinlock_t *__lock);
00404 extern int __pthread_spin_trylock (pthread_spinlock_t *__lock);
00405 extern int __pthread_spin_unlock (pthread_spinlock_t *__lock);
00406 extern int __pthread_spin_init (pthread_spinlock_t *__lock, int __pshared);
00407 extern int __pthread_spin_destroy (pthread_spinlock_t *__lock);
00408 
00409 /* Global pointers to old or new suspend functions */
00410 
00411 extern void (*__pthread_restart)(pthread_descr);
00412 extern void (*__pthread_suspend)(pthread_descr);
00413 extern int (*__pthread_timedsuspend)(pthread_descr, const struct timespec *);
00414 
00415 /* Prototypes for the function without cancelation support when the
00416    normal version has it.  */
00417 extern int __libc_close (int fd);
00418 extern int __libc_nanosleep (const struct timespec *requested_time,
00419                           struct timespec *remaining);
00420 /* Prototypes for some of the new semaphore functions.  */
00421 extern int __new_sem_post (sem_t * sem);
00422 extern int __new_sem_init (sem_t *__sem, int __pshared, unsigned int __value);
00423 extern int __new_sem_wait (sem_t *__sem);
00424 extern int __new_sem_trywait (sem_t *__sem);
00425 extern int __new_sem_getvalue (sem_t *__restrict __sem, int *__restrict __sval);
00426 extern int __new_sem_destroy (sem_t *__sem);
00427 
00428 /* Prototypes for compatibility functions.  */
00429 extern int __pthread_attr_init_2_1 (pthread_attr_t *__attr);
00430 extern int __pthread_attr_init_2_0 (pthread_attr_t *__attr);
00431 extern int __pthread_create_2_1 (pthread_t *__restrict __threadp,
00432                              const pthread_attr_t *__attr,
00433                              void *(*__start_routine) (void *),
00434                              void *__restrict __arg);
00435 extern int __pthread_create_2_0 (pthread_t *__restrict thread,
00436                              const pthread_attr_t *__attr,
00437                              void *(*__start_routine) (void *),
00438                              void *__restrict arg);
00439 
00440 /* The functions called the signal events.  */
00441 extern void __linuxthreads_create_event (void);
00442 extern void __linuxthreads_death_event (void);
00443 extern void __linuxthreads_reap_event (void);
00444 
00445 /* This function is called to initialize the pthread library.  */
00446 extern void __pthread_initialize (void);
00447 
00448 /* TSD.  */
00449 extern int __pthread_internal_tsd_set (int key, const void * pointer);
00450 extern void * __pthread_internal_tsd_get (int key);
00451 extern void ** __attribute__ ((__const__))
00452   __pthread_internal_tsd_address (int key);
00453 
00454 /* Sighandler wrappers.  */
00455 extern void __pthread_sighandler(int signo, SIGCONTEXT ctx);
00456 extern void __pthread_sighandler_rt(int signo, struct siginfo *si,
00457                                 struct ucontext *uc);
00458 extern void __pthread_null_sighandler(int sig);
00459 extern int __pthread_sigaction (int sig, const struct sigaction *act,
00460                             struct sigaction *oact);
00461 extern int __pthread_sigwait (const sigset_t *set, int *sig);
00462 extern int __pthread_raise (int sig);
00463 
00464 /* Cancellation.  */
00465 extern int __pthread_enable_asynccancel (void) attribute_hidden;
00466 extern void __pthread_disable_asynccancel (int oldtype)
00467   internal_function attribute_hidden;
00468 
00469 /* The two functions are in libc.so and not exported.  */
00470 extern int __libc_enable_asynccancel (void) attribute_hidden;
00471 extern void __libc_disable_asynccancel (int oldtype)
00472   internal_function attribute_hidden;
00473 
00474 /* The two functions are in libc.so and are exported.  */
00475 extern int __librt_enable_asynccancel (void);
00476 extern void __librt_disable_asynccancel (int oldtype) internal_function;
00477 
00478 extern void __pthread_cleanup_upto (__jmp_buf target,
00479                                 char *targetframe) attribute_hidden;
00480 extern pid_t __pthread_fork (struct fork_block *b) attribute_hidden;
00481 
00482 #if !defined NOT_IN_libc
00483 # define LIBC_CANCEL_ASYNC() \
00484   __libc_enable_asynccancel ()
00485 # define LIBC_CANCEL_RESET(oldtype) \
00486   __libc_disable_asynccancel (oldtype)
00487 # define LIBC_CANCEL_HANDLED() \
00488   __asm (".globl " __SYMBOL_PREFIX "__libc_enable_asynccancel"); \
00489   __asm (".globl " __SYMBOL_PREFIX "__libc_disable_asynccancel")
00490 #elif defined IS_IN_libpthread
00491 # define LIBC_CANCEL_ASYNC() \
00492   __pthread_enable_asynccancel ()
00493 # define LIBC_CANCEL_RESET(oldtype) \
00494   __pthread_disable_asynccancel (oldtype)
00495 # define LIBC_CANCEL_HANDLED() \
00496   __asm (".globl " __SYMBOL_PREFIX "__pthread_enable_asynccancel"); \
00497   __asm (".globl " __SYMBOL_PREFIX "__pthread_disable_asynccancel")
00498 #elif defined IS_IN_librt
00499 # define LIBC_CANCEL_ASYNC() \
00500   __librt_enable_asynccancel ()
00501 # define LIBC_CANCEL_RESET(oldtype) \
00502   __librt_disable_asynccancel (oldtype)
00503 # define LIBC_CANCEL_HANDLED() \
00504   __asm (".globl " __SYMBOL_PREFIX "__librt_enable_asynccancel"); \
00505   __asm (".globl " __SYMBOL_PREFIX "__librt_disable_asynccancel")
00506 #else
00507 # define LIBC_CANCEL_ASYNC()    0 /* Just a dummy value.  */
00508 # define LIBC_CANCEL_RESET(val) ((void)(val)) /* Nothing, but evaluate it.  */
00509 # define LIBC_CANCEL_HANDLED()     /* Nothing.  */
00510 #endif
00511 
00512 extern int * __libc_pthread_init (const struct pthread_functions *functions);
00513 
00514 #if !defined NOT_IN_libc && !defined FLOATING_STACKS
00515 # ifdef SHARED
00516 #  define thread_self() \
00517   (*__libc_pthread_functions.ptr_pthread_thread_self) ()
00518 # else
00519 weak_extern (__pthread_thread_self)
00520 #  define thread_self() __pthread_thread_self ()
00521 # endif
00522 #endif
00523 
00524 #ifndef USE_TLS
00525 # define __manager_thread (&__pthread_manager_thread)
00526 #else
00527 # define __manager_thread __pthread_manager_threadp
00528 #endif
00529 
00530 extern inline __attribute__((always_inline)) pthread_descr
00531 check_thread_self (void)
00532 {
00533   pthread_descr self = thread_self ();
00534 #if defined THREAD_SELF && defined INIT_THREAD_SELF
00535   if (self == __manager_thread)
00536     {
00537       /* A new thread might get a cancel signal before it is fully
00538         initialized, so that the thread register might still point to the
00539         manager thread.  Double check that this is really the manager
00540         thread.  */
00541       self = __pthread_self_stack();
00542       if (self != __manager_thread)
00543        /* Oops, thread_self() isn't working yet..  */
00544        INIT_THREAD_SELF(self, self->p_nr);
00545     }
00546 #endif
00547   return self;
00548 }
00549 
00550 #endif /* internals.h */