Changes and additions migrated from cvs.devel.redhat.com:/cvs/devel/glibc to fedora...
[glibc.git] / linuxthreads / sysdeps / sparc / tls.h
blob50538240585b94bcd35eb7a2c5a5ea0b46bf3a56
1 /* Definitions for thread-local data handling. linuxthreads/sparc version.
2 Copyright (C) 2002, 2003 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, write to the Free
17 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
18 02111-1307 USA. */
20 #ifndef _TLS_H
21 #define _TLS_H
23 #ifndef __ASSEMBLER__
25 # include <pt-machine.h>
26 # include <stddef.h>
28 /* Type for the dtv. */
29 typedef union dtv
31 size_t counter;
32 void *pointer;
33 } dtv_t;
35 typedef struct
37 void *tcb; /* Pointer to the TCB. Not necessary the
38 thread descriptor used by libpthread. */
39 dtv_t *dtv;
40 void *self; /* Pointer to the thread descriptor. */
41 int multiple_threads;
42 } tcbhead_t;
44 #else /* __ASSEMBLER__ */
45 # include <tcb-offsets.h>
46 #endif /* __ASSEMBLER__ */
48 #ifdef HAVE_TLS_SUPPORT
50 /* Signal that TLS support is available. */
51 # define USE_TLS 1
53 # ifndef __ASSEMBLER__
54 /* Get system call information. */
55 # include <sysdep.h>
57 /* Get the thread descriptor definition. */
58 # include <linuxthreads/descr.h>
60 /* This is the size of the initial TCB. */
61 # define TLS_INIT_TCB_SIZE sizeof (tcbhead_t)
63 /* Alignment requirements for the initial TCB. */
64 # define TLS_INIT_TCB_ALIGN __alignof__ (tcbhead_t)
66 /* This is the size of the TCB. */
67 # ifndef IS_IN_rtld
68 # define TLS_TCB_SIZE sizeof (struct _pthread_descr_struct)
69 # else
70 # include <nptl-struct-pthread.h>
71 # define TLS_TCB_SIZE \
72 (sizeof (struct _pthread_descr_struct) > NPTL_STRUCT_PTHREAD_SIZE \
73 ? sizeof (struct _pthread_descr_struct) : NPTL_STRUCT_PTHREAD_SIZE)
74 # endif
76 /* Alignment requirements for the TCB. */
77 # define TLS_TCB_ALIGN __alignof__ (struct _pthread_descr_struct)
79 /* The TCB can have any size and the memory following the address the
80 thread pointer points to is unspecified. Allocate the TCB there. */
81 # define TLS_TCB_AT_TP 1
83 /* Install the dtv pointer. The pointer passed is to the element with
84 index -1 which contain the length. */
85 # define INSTALL_DTV(descr, dtvp) \
86 ((tcbhead_t *) (descr))->dtv = (dtvp) + 1
88 /* Install new dtv for current thread. */
89 # define INSTALL_NEW_DTV(DTV) \
90 (((tcbhead_t *) __thread_self)->dtv = (DTV))
92 /* Return dtv of given thread descriptor. */
93 # define GET_DTV(descr) \
94 (((tcbhead_t *) (descr))->dtv)
96 /* Code to initially initialize the thread pointer. */
97 # define TLS_INIT_TP(descr, secondcall) \
98 (__thread_self = (__typeof (__thread_self)) (descr), NULL)
100 /* Return the address of the dtv for the current thread. */
101 # define THREAD_DTV() \
102 (((tcbhead_t *) __thread_self)->dtv)
104 # endif
106 #else
108 # define NONTLS_INIT_TP \
109 do { \
110 static const tcbhead_t nontls_init_tp \
111 = { .multiple_threads = 0 }; \
112 __thread_self = (__typeof (__thread_self)) &nontls_init_tp; \
113 } while (0)
115 #endif /* USE_TLS */
117 #endif /* tls.h */