2.3.5-9
[glibc.git] / linuxthreads / sysdeps / sparc / tls.h
blob3e550fa7c7e86f29286ac1af758a1301810514dd
1 /* Definitions for thread-local data handling. linuxthreads/sparc version.
2 Copyright (C) 2002, 2003, 2005 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 <stdbool.h>
27 # include <stddef.h>
29 /* Type for the dtv. */
30 typedef union dtv
32 size_t counter;
33 struct
35 void *val;
36 bool is_static;
37 } pointer;
38 } dtv_t;
40 typedef struct
42 void *tcb; /* Pointer to the TCB. Not necessary the
43 thread descriptor used by libpthread. */
44 dtv_t *dtv;
45 void *self; /* Pointer to the thread descriptor. */
46 int multiple_threads;
47 } tcbhead_t;
49 #else /* __ASSEMBLER__ */
50 # include <tcb-offsets.h>
51 #endif /* __ASSEMBLER__ */
53 #ifdef HAVE_TLS_SUPPORT
55 /* Signal that TLS support is available. */
56 # define USE_TLS 1
58 # ifndef __ASSEMBLER__
59 /* Get system call information. */
60 # include <sysdep.h>
62 /* Get the thread descriptor definition. */
63 # include <linuxthreads/descr.h>
65 /* This is the size of the initial TCB. */
66 # define TLS_INIT_TCB_SIZE sizeof (tcbhead_t)
68 /* Alignment requirements for the initial TCB. */
69 # define TLS_INIT_TCB_ALIGN __alignof__ (tcbhead_t)
71 /* This is the size of the TCB. */
72 # ifndef IS_IN_rtld
73 # define TLS_TCB_SIZE sizeof (struct _pthread_descr_struct)
74 # else
75 # include <nptl-struct-pthread.h>
76 # define TLS_TCB_SIZE \
77 (sizeof (struct _pthread_descr_struct) > NPTL_STRUCT_PTHREAD_SIZE \
78 ? sizeof (struct _pthread_descr_struct) : NPTL_STRUCT_PTHREAD_SIZE)
79 # endif
81 /* Alignment requirements for the TCB. */
82 # define TLS_TCB_ALIGN __alignof__ (struct _pthread_descr_struct)
84 /* The TCB can have any size and the memory following the address the
85 thread pointer points to is unspecified. Allocate the TCB there. */
86 # define TLS_TCB_AT_TP 1
88 /* Install the dtv pointer. The pointer passed is to the element with
89 index -1 which contain the length. */
90 # define INSTALL_DTV(descr, dtvp) \
91 ((tcbhead_t *) (descr))->dtv = (dtvp) + 1
93 /* Install new dtv for current thread. */
94 # define INSTALL_NEW_DTV(DTV) \
95 (((tcbhead_t *) __thread_self)->dtv = (DTV))
97 /* Return dtv of given thread descriptor. */
98 # define GET_DTV(descr) \
99 (((tcbhead_t *) (descr))->dtv)
101 /* Code to initially initialize the thread pointer. */
102 # define TLS_INIT_TP(descr, secondcall) \
103 (__thread_self = (__typeof (__thread_self)) (descr), NULL)
105 /* Return the address of the dtv for the current thread. */
106 # define THREAD_DTV() \
107 (((tcbhead_t *) __thread_self)->dtv)
109 # endif
111 #else
113 # define NONTLS_INIT_TP \
114 do { \
115 static const tcbhead_t nontls_init_tp \
116 = { .multiple_threads = 0 }; \
117 __thread_self = (__typeof (__thread_self)) &nontls_init_tp; \
118 } while (0)
120 #endif /* USE_TLS */
122 #endif /* tls.h */