1 /* Copyright (C) 2002 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
3 Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
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
27 #include <sys/types.h>
28 #include <hp-timing.h>
30 #include <lowlevellock.h>
31 #include <pthreaddef.h>
32 #include <dl-sysdep.h>
33 #include "../nptl_db/thread_db.h"
37 # define TCB_ALIGNMENT sizeof (double)
41 /* We keep thread specific data in a special data structure, a two-level
42 array. The top-level array contains pointers to dynamically allocated
43 arrays of a certain number of data pointers. So we can implement a
44 sparse array. Each dynamic second-level array has
45 PTHREAD_KEY_2NDLEVEL_SIZE
46 entries. This value shouldn't be too large. */
47 #define PTHREAD_KEY_2NDLEVEL_SIZE 32
49 /* We need to address PTHREAD_KEYS_MAX key with PTHREAD_KEY_2NDLEVEL_SIZE
50 keys in each subarray. */
51 #define PTHREAD_KEY_1STLEVEL_SIZE \
52 ((PTHREAD_KEYS_MAX + PTHREAD_KEY_2NDLEVEL_SIZE - 1) \
53 / PTHREAD_KEY_2NDLEVEL_SIZE)
56 /* Thread descriptor data structure. */
59 /* XXX Remove this union for IA-64 style TLS module */
62 /* It is very important to always append new elements. The offsets
63 of some of the elements of the struct are used in assembler code. */
66 void *tcb
; /* Pointer to the TCB. This is not always
67 the address of this thread descriptor. */
69 struct pthread
*self
; /* Pointer to this structure */
71 #ifdef NEED_DL_SYSINFO
79 /* Two-level array for the thread-specific data. */
80 struct pthread_key_data
82 /* Sequence number. We use uintptr_t to not require padding on
83 32- and 64-bit machines. On 64-bit machines it helps to avoid
89 } *specific
[PTHREAD_KEY_1STLEVEL_SIZE
];
90 /* We allocate one block of references here. This should be enough
91 to avoid allocating any memory dynamically for most applications. */
92 struct pthread_key_data specific_1stblock
[PTHREAD_KEY_2NDLEVEL_SIZE
];
93 /* Flag which is set when specific data is set. */
96 /* True if the user provided the stack. */
99 /* True if events must be reported. */
102 /* Lock to syncronize access to the descriptor. */
106 /* Offset of the CPU clock at start thread start time. */
107 hp_timing_t cpuclock_offset
;
110 /* If the thread waits to join another one the ID of the latter is
113 In case a thread is detached this field contains a pointer of the
114 TCB if the thread itself. This is something which cannot happen
115 in normal operation. */
116 struct pthread
*joinid
;
117 /* Check whether a thread is detached. */
118 #define IS_DETACHED(pd) ((pd)->joinid == (pd))
120 /* List of cleanup buffers. */
121 struct _pthread_cleanup_buffer
*cleanup
;
122 /* Flags determining processing of cancellation. */
124 /* Bit set if cancellation is disabled. */
125 #define CANCELSTATE_BIT 0
126 #define CANCELSTATE_BITMASK 0x01
127 /* Bit set if asynchronous cancellation mode is selected. */
128 #define CANCELTYPE_BIT 1
129 #define CANCELTYPE_BITMASK 0x02
130 /* Bit set if canceled. */
131 #define CANCELED_BIT 2
132 #define CANCELED_BITMASK 0x04
133 /* Bit set if thread is exiting. */
134 #define EXITING_BIT 3
135 #define EXITING_BITMASK 0x08
136 /* Bit set if thread terminated and TCB is freed. */
137 #define TERMINATED_BIT 4
138 #define TERMINATED_BITMASK 0x10
139 /* Mask for the rest. Helps the compiler to optimize. */
140 #define CANCEL_RESTMASK 0xffffffe0
142 #define CANCEL_ENABLED_AND_CANCELED(value) \
143 (((value) & (CANCELSTATE_BITMASK | CANCELED_BITMASK | EXITING_BITMASK \
144 | CANCEL_RESTMASK | TERMINATED_BITMASK)) == CANCELED_BITMASK)
145 #define CANCEL_ENABLED_AND_CANCELED_AND_ASYNCHRONOUS(value) \
146 (((value) & (CANCELSTATE_BITMASK | CANCELTYPE_BITMASK | CANCELED_BITMASK \
147 | EXITING_BITMASK | CANCEL_RESTMASK | TERMINATED_BITMASK)) \
148 == (CANCELTYPE_BITMASK | CANCELED_BITMASK))
149 /* Setjmp buffer to be used if try/finally is not available. */
150 sigjmp_buf cancelbuf
;
151 #define HAVE_CANCELBUF 1
153 /* Thread ID - which is also a 'is this thread descriptor (and
154 therefore stack) used' flag. */
157 /* Flags. Including those copied from the thread attribute. */
160 /* The result of the thread function. */
163 /* Scheduling parameters for the new thread. */
164 struct sched_param schedparam
;
167 /* Start position of the code to be executed and the argument passed
169 void *(*start_routine
) (void *);
173 td_eventbuf_t eventbuf
;
174 /* Next descriptor with a pending event. */
175 struct pthread
*nextevent
;
177 /* If nonzero pointer to area allocated for the stack and its
180 size_t stackblock_size
;
181 /* Size of the included guard area. */
183 } __attribute ((aligned (TCB_ALIGNMENT
)));