From 1b37ff3740644d3febf6ae6e7f756a8d152a37e6 Mon Sep 17 00:00:00 2001 From: Samuel Thibault Date: Wed, 13 Jun 2007 00:00:00 +0200 Subject: TLS support for libpthread, Mach/Hurd (x86). * Makefile (CFLAGS): Define ENABLE_TLS. * pthread/pt-create.c (__pthread_create_internal) [ENABLE_TLS]: Call into glibc to allocate static TLS block. * pthread/pt-exit.c (pthread_exit) [ENABLE_TLS]: Call into glibc to deallocate static TLS block. * pthread/pt-internal.h [ENABLE_TLS] (tcbhead_t): New structure; as in glibc. (__pthread) [ENABLE_TLS]: Add TCB member. [ENABLE_TLS] (_dl_allocate_tls, _dl_deallocate_tls): Declare; from glibc. * sysdeps/mach/hurd/pt-sysdep.h (__thread_set_pcsp): Rename to __thread_set_pcsptp. Add SET_TP and TP parameters. Change all callers. * sysdeps/mach/hurd/i386/pt-machdep.c (__thread_set_pcsptp): Imlement TLS support. * sysdeps/mach/hurd/i386/pt-setup.c (__pthread_setup): Likewise. --- pthread/pt-create.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'pthread/pt-create.c') diff --git a/pthread/pt-create.c b/pthread/pt-create.c index bad5d83f..0d66d6ce 100644 --- a/pthread/pt-create.c +++ b/pthread/pt-create.c @@ -1,5 +1,5 @@ /* Thread creation. - Copyright (C) 2000, 2002, 2005 Free Software Foundation, Inc. + Copyright (C) 2000, 2002, 2005, 2007 Free Software Foundation, Inc. This file is part of the GNU C Library. The GNU C Library is free software; you can redistribute it and/or @@ -127,6 +127,13 @@ __pthread_create_internal (struct __pthread **thread, if (err) goto failed_thread_alloc; +#ifdef ENABLE_TLS + pthread->tcb = _dl_allocate_tls (NULL); + if (!pthread->tcb) + goto failed_thread_tls_alloc; + pthread->tcb->tcb = pthread->tcb; +#endif /* ENABLE_TLS */ + /* And initialize the rest of the machine context. This may include additional machine- and system-specific initializations that prove convenient. */ @@ -192,6 +199,10 @@ __pthread_create_internal (struct __pthread **thread, failed_sigstate: __pthread_sigstate_destroy (pthread); failed_setup: +#ifdef ENABLE_TLS + _dl_deallocate_tls (pthread->tcb, 1); + failed_thread_tls_alloc: +#endif /* ENABLE_TLS */ __pthread_thread_dealloc (pthread); __pthread_thread_halt (pthread, 0); failed_thread_alloc: -- cgit v1.2.3