* sysdeps/unix/sysv/linux/m68k/semtimedop.S: New file.
[glibc/pb-stable.git] / nptl / descr.h
blobefb25c7479c236ba897a8d36edd0c5a58e880958
1 /* Copyright (C) 2002, 2003 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
18 02111-1307 USA. */
20 #ifndef _DESCR_H
21 #define _DESCR_H 1
23 #include <limits.h>
24 #include <sched.h>
25 #include <setjmp.h>
26 #include <stdbool.h>
27 #include <sys/types.h>
28 #include <hp-timing.h>
29 #include <list.h>
30 #include <lowlevellock.h>
31 #include <pthreaddef.h>
32 #include <dl-sysdep.h>
33 #include "../nptl_db/thread_db.h"
34 #include <tls.h>
35 #ifdef HAVE_FORCED_UNWIND
36 # include <unwind.h>
37 #endif
40 #ifndef TCB_ALIGNMENT
41 # define TCB_ALIGNMENT sizeof (double)
42 #endif
45 /* We keep thread specific data in a special data structure, a two-level
46 array. The top-level array contains pointers to dynamically allocated
47 arrays of a certain number of data pointers. So we can implement a
48 sparse array. Each dynamic second-level array has
49 PTHREAD_KEY_2NDLEVEL_SIZE
50 entries. This value shouldn't be too large. */
51 #define PTHREAD_KEY_2NDLEVEL_SIZE 32
53 /* We need to address PTHREAD_KEYS_MAX key with PTHREAD_KEY_2NDLEVEL_SIZE
54 keys in each subarray. */
55 #define PTHREAD_KEY_1STLEVEL_SIZE \
56 ((PTHREAD_KEYS_MAX + PTHREAD_KEY_2NDLEVEL_SIZE - 1) \
57 / PTHREAD_KEY_2NDLEVEL_SIZE)
62 /* Internal version of the buffer to store cancellation handler
63 information. */
64 struct pthread_unwind_buf
66 struct
68 __jmp_buf jmp_buf;
69 int mask_was_saved;
70 } cancel_jmp_buf[1];
72 union
74 /* This is the placeholder of the public version. */
75 void *pad[4];
77 struct
79 /* Pointer to the previous cleanup buffer. */
80 __pthread_unwind_buf_t *prev;
82 /* Backward compatibility: state of the old-style cleanup
83 handler at the time of the previous new-style cleanup handler
84 installment. */
85 struct _pthread_cleanup_buffer *cleanup;
87 /* Cancellation type before the push call. */
88 int canceltype;
89 } data;
90 } priv;
94 /* Thread descriptor data structure. */
95 struct pthread
97 union
99 #if !TLS_DTV_AT_TP
100 /* This overlaps the TCB as used for TLS without threads (see tls.h). */
101 tcbhead_t header;
102 #elif TLS_MULTIPLE_THREADS_IN_TCB
103 struct
105 int multiple_threads;
106 } header;
107 #endif
109 /* This extra padding has no special purpose, and this structure layout
110 is private and subject to change without affecting the official ABI.
111 We just have it here in case it might be convenient for some
112 implementation-specific instrumentation hack or suchlike. */
113 void *__padding[16];
116 /* This descriptor's link on the `stack_used' or `__stack_user' list. */
117 list_t list;
119 /* Thread ID - which is also a 'is this thread descriptor (and
120 therefore stack) used' flag. */
121 pid_t tid;
123 /* List of cleanup buffers. */
124 struct _pthread_cleanup_buffer *cleanup;
126 /* Unwind information. */
127 __pthread_unwind_buf_t *cleanup_jmp_buf;
128 #define HAVE_CLEANUP_JMP_BUF
130 /* Flags determining processing of cancellation. */
131 int cancelhandling;
132 /* Bit set if cancellation is disabled. */
133 #define CANCELSTATE_BIT 0
134 #define CANCELSTATE_BITMASK 0x01
135 /* Bit set if asynchronous cancellation mode is selected. */
136 #define CANCELTYPE_BIT 1
137 #define CANCELTYPE_BITMASK 0x02
138 /* Bit set if canceling has been initiated. */
139 #define CANCELING_BIT 2
140 #define CANCELING_BITMASK 0x04
141 /* Bit set if canceled. */
142 #define CANCELED_BIT 3
143 #define CANCELED_BITMASK 0x08
144 /* Bit set if thread is exiting. */
145 #define EXITING_BIT 4
146 #define EXITING_BITMASK 0x10
147 /* Bit set if thread terminated and TCB is freed. */
148 #define TERMINATED_BIT 5
149 #define TERMINATED_BITMASK 0x20
150 /* Mask for the rest. Helps the compiler to optimize. */
151 #define CANCEL_RESTMASK 0xffffffc0
153 #define CANCEL_ENABLED_AND_CANCELED(value) \
154 (((value) & (CANCELSTATE_BITMASK | CANCELED_BITMASK | EXITING_BITMASK \
155 | CANCEL_RESTMASK | TERMINATED_BITMASK)) == CANCELED_BITMASK)
156 #define CANCEL_ENABLED_AND_CANCELED_AND_ASYNCHRONOUS(value) \
157 (((value) & (CANCELSTATE_BITMASK | CANCELTYPE_BITMASK | CANCELED_BITMASK \
158 | EXITING_BITMASK | CANCEL_RESTMASK | TERMINATED_BITMASK)) \
159 == (CANCELTYPE_BITMASK | CANCELED_BITMASK))
161 /* We allocate one block of references here. This should be enough
162 to avoid allocating any memory dynamically for most applications. */
163 struct pthread_key_data
165 /* Sequence number. We use uintptr_t to not require padding on
166 32- and 64-bit machines. On 64-bit machines it helps to avoid
167 wrapping, too. */
168 uintptr_t seq;
170 /* Data pointer. */
171 void *data;
172 } specific_1stblock[PTHREAD_KEY_2NDLEVEL_SIZE];
174 /* Flag which is set when specific data is set. */
175 bool specific_used;
177 /* Two-level array for the thread-specific data. */
178 struct pthread_key_data *specific[PTHREAD_KEY_1STLEVEL_SIZE];
180 /* True if events must be reported. */
181 bool report_events;
183 /* True if the user provided the stack. */
184 bool user_stack;
186 /* Lock to synchronize access to the descriptor. */
187 lll_lock_t lock;
189 #if HP_TIMING_AVAIL
190 /* Offset of the CPU clock at start thread start time. */
191 hp_timing_t cpuclock_offset;
192 #endif
194 /* If the thread waits to join another one the ID of the latter is
195 stored here.
197 In case a thread is detached this field contains a pointer of the
198 TCB if the thread itself. This is something which cannot happen
199 in normal operation. */
200 struct pthread *joinid;
201 /* Check whether a thread is detached. */
202 #define IS_DETACHED(pd) ((pd)->joinid == (pd))
204 /* Flags. Including those copied from the thread attribute. */
205 int flags;
207 /* The result of the thread function. */
208 void *result;
210 /* Scheduling parameters for the new thread. */
211 struct sched_param schedparam;
212 int schedpolicy;
214 /* Start position of the code to be executed and the argument passed
215 to the function. */
216 void *(*start_routine) (void *);
217 void *arg;
219 /* Debug state. */
220 td_eventbuf_t eventbuf;
221 /* Next descriptor with a pending event. */
222 struct pthread *nextevent;
224 #ifdef HAVE_FORCED_UNWIND
225 /* Machine-specific unwind info. */
226 struct _Unwind_Exception exc;
227 #endif
229 /* If nonzero pointer to area allocated for the stack and its
230 size. */
231 void *stackblock;
232 size_t stackblock_size;
233 /* Size of the included guard area. */
234 size_t guardsize;
235 } __attribute ((aligned (TCB_ALIGNMENT)));
238 #endif /* descr.h */