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 "../nptl_db/thread_db.h"
36 # define TCB_ALIGNMENT sizeof (double)
40 /* We keep thread specific data in a special data structure, a two-level
41 array. The top-level array contains pointers to dynamically allocated
42 arrays of a certain number of data pointers. So we can implement a
43 sparse array. Each dynamic second-level array has
44 PTHREAD_KEY_2NDLEVEL_SIZE
45 entries. This value shouldn't be too large. */
46 #define PTHREAD_KEY_2NDLEVEL_SIZE 32
48 /* We need to address PTHREAD_KEYS_MAX key with PTHREAD_KEY_2NDLEVEL_SIZE
49 keys in each subarray. */
50 #define PTHREAD_KEY_1STLEVEL_SIZE \
51 ((PTHREAD_KEYS_MAX + PTHREAD_KEY_2NDLEVEL_SIZE - 1) \
52 / PTHREAD_KEY_2NDLEVEL_SIZE)
55 /* Thread descriptor data structure. */
58 /* XXX Remove this union for IA-64 style TLS module */
61 /* It is very important to always append new elements. The offsets
62 of some of the elements of the struct are used in assembler code. */
65 void *tcb
; /* Pointer to the TCB. This is not always
66 the address of this thread descriptor. */
68 struct pthread
*self
; /* Pointer to this structure */
75 /* Two-level array for the thread-specific data. */
76 struct pthread_key_data
78 /* Sequence number. We use uintptr_t to not require padding on
79 32- and 64-bit machines. On 64-bit machines it helps to avoid
85 } *specific
[PTHREAD_KEY_1STLEVEL_SIZE
];
86 /* We allocate one block of references here. This should be enough
87 to avoid allocating any memory dynamically for most applications. */
88 struct pthread_key_data specific_1stblock
[PTHREAD_KEY_2NDLEVEL_SIZE
];
89 /* Flag which is set when specific data is set. */
92 /* True if the user provided the stack. */
95 /* True if events must be reported. */
98 /* Lock to syncronize access to the descriptor. */
102 /* Offset of the CPU clock at start thread start time. */
103 hp_timing_t cpuclock_offset
;
106 /* If the thread waits to join another one the ID of the latter is
109 In case a thread is detached this field contains a pointer of the
110 TCB if the thread itself. This is something which cannot happen
111 in normal operation. */
112 struct pthread
*joinid
;
113 /* Check whether a thread is detached. */
114 #define IS_DETACHED(pd) ((pd)->joinid == (pd))
116 /* List of cleanup buffers. */
117 struct _pthread_cleanup_buffer
*cleanup
;
118 /* Flags determining processing of cancellation. */
120 /* Bit set if cancellation is disabled. */
121 #define CANCELSTATE_BIT 0
122 #define CANCELSTATE_BITMASK 0x01
123 /* Bit set if asynchronous cancellation mode is selected. */
124 #define CANCELTYPE_BIT 1
125 #define CANCELTYPE_BITMASK 0x02
126 /* Bit set if canceled. */
127 #define CANCELED_BIT 2
128 #define CANCELED_BITMASK 0x04
129 /* Bit set if thread is exiting. */
130 #define EXITING_BIT 3
131 #define EXITING_BITMASK 0x08
132 /* Bit set if thread terminated and TCB is freed. */
133 #define TERMINATED_BIT 4
134 #define TERMINATED_BITMASK 0x10
135 /* Mask for the rest. Helps the compiler to optimize. */
136 #define CANCEL_RESTMASK 0xffffffe0
138 #define CANCEL_ENABLED_AND_CANCELED(value) \
139 (((value) & (CANCELSTATE_BITMASK | CANCELED_BITMASK | EXITING_BITMASK \
140 | CANCEL_RESTMASK | TERMINATED_BITMASK)) == CANCELED_BITMASK)
141 #define CANCEL_ENABLED_AND_CANCELED_AND_ASYNCHRONOUS(value) \
142 (((value) & (CANCELSTATE_BITMASK | CANCELTYPE_BITMASK | CANCELED_BITMASK \
143 | EXITING_BITMASK | CANCEL_RESTMASK | TERMINATED_BITMASK)) \
144 == (CANCELTYPE_BITMASK | CANCELED_BITMASK))
145 /* Setjmp buffer to be used if try/finally is not available. */
146 sigjmp_buf cancelbuf
;
147 #define HAVE_CANCELBUF 1
149 /* Thread ID - which is also a 'is this thread descriptor (and
150 therefore stack) used' flag. */
153 /* Flags. Including those copied from the thread attribute. */
156 /* The result of the thread function. */
159 /* Scheduling parameters for the new thread. */
160 struct sched_param schedparam
;
163 /* Start position of the code to be executed and the argument passed
165 void *(*start_routine
) (void *);
169 td_eventbuf_t eventbuf
;
170 /* Next descriptor with a pending event. */
171 struct pthread
*nextevent
;
173 /* If nonzero pointer to area allocated for the stack and its
176 size_t stackblock_size
;
177 /* Size of the included guard area. */
179 } __attribute ((aligned (TCB_ALIGNMENT
)));