* sysdeps/unix/sysv/linux/m68k/clone.S: Make inline syscall to
[glibc.git] / nptl / descr.h
blob3dd6e1293c3d7449c036f61c33f69453bd76b16c
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
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 "../nptl_db/thread_db.h"
35 #ifndef TCB_ALIGNMENT
36 # define TCB_ALIGNMENT sizeof (double)
37 #endif
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. */
56 struct pthread
58 /* XXX Remove this union for IA-64 style TLS module */
59 union
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. */
63 struct
65 void *tcb; /* Pointer to the TCB. This is not always
66 the address of this thread descriptor. */
67 union dtv *dtvp;
68 struct pthread *self; /* Pointer to this structure */
69 list_t list;
70 int multiple_threads;
71 } data;
72 void *__padding[16];
73 } header;
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
80 wrapping, too. */
81 uintptr_t seq;
83 /* Data pointer. */
84 void *data;
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. */
90 bool specific_used;
92 /* True if the user provided the stack. */
93 bool user_stack;
95 /* True if events must be reported. */
96 bool report_events;
98 /* Lock to syncronize access to the descriptor. */
99 lll_lock_t lock;
101 #if HP_TIMING_AVAIL
102 /* Offset of the CPU clock at start thread start time. */
103 hp_timing_t cpuclock_offset;
104 #endif
106 /* If the thread waits to join another one the ID of the latter is
107 stored here.
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. */
119 int cancelhandling;
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. */
151 pid_t tid;
153 /* Flags. Including those copied from the thread attribute. */
154 int flags;
156 /* The result of the thread function. */
157 void *result;
159 /* Scheduling parameters for the new thread. */
160 struct sched_param schedparam;
161 int schedpolicy;
163 /* Start position of the code to be executed and the argument passed
164 to the function. */
165 void *(*start_routine) (void *);
166 void *arg;
168 /* Debug state. */
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
174 size. */
175 void *stackblock;
176 size_t stackblock_size;
177 /* Size of the included guard area. */
178 size_t guardsize;
179 } __attribute ((aligned (TCB_ALIGNMENT)));
182 #endif /* descr.h */