* sysdeps/m68k/fpu/bits/mathinline.h (isgreater, isgreaterequal)
[glibc.git] / linuxthreads / descr.h
blobcc64cbc8aa0ec3bba0c5efeec135e9f092005f60
1 /* Linuxthreads - a simple clone()-based implementation of Posix */
2 /* threads for Linux. */
3 /* Copyright (C) 1996 Xavier Leroy (Xavier.Leroy@inria.fr) */
4 /* */
5 /* This program is free software; you can redistribute it and/or */
6 /* modify it under the terms of the GNU Library General Public License */
7 /* as published by the Free Software Foundation; either version 2 */
8 /* of the License, or (at your option) any later version. */
9 /* */
10 /* This program 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 */
13 /* GNU Library General Public License for more details. */
15 #ifndef _DESCR_H
16 #define _DESCR_H 1
18 #define __need_res_state
19 #include <resolv.h>
20 #include <sched.h>
21 #include <setjmp.h>
22 #include <signal.h>
23 #include <sys/types.h>
24 #include <hp-timing.h>
25 #include <bits/libc-tsd.h> /* for _LIBC_TSD_KEY_N */
28 /* The type of thread descriptors */
29 typedef struct _pthread_descr_struct *pthread_descr;
32 /* Some more includes. */
33 #include <pt-machine.h>
34 #include <linuxthreads_db/thread_dbP.h>
37 /* Arguments passed to thread creation routine */
38 struct pthread_start_args {
39 void *(*start_routine)(void *); /* function to run */
40 void *arg; /* its argument */
41 sigset_t mask; /* initial signal mask for thread */
42 int schedpolicy; /* initial scheduling policy (if any) */
43 struct sched_param schedparam; /* initial scheduling parameters (if any) */
47 /* Callback interface for removing the thread from waiting on an
48 object if it is cancelled while waiting or about to wait.
49 This hold a pointer to the object, and a pointer to a function
50 which ``extricates'' the thread from its enqueued state.
51 The function takes two arguments: pointer to the wait object,
52 and a pointer to the thread. It returns 1 if an extrication
53 actually occured, and hence the thread must also be signalled.
54 It returns 0 if the thread had already been extricated. */
55 typedef struct _pthread_extricate_struct {
56 void *pu_object;
57 int (*pu_extricate_func)(void *, pthread_descr);
58 } pthread_extricate_if;
61 /* Atomic counter made possible by compare_and_swap */
62 struct pthread_atomic {
63 long p_count;
64 int p_spinlock;
68 /* Context info for read write locks. The pthread_rwlock_info structure
69 is information about a lock that has been read-locked by the thread
70 in whose list this structure appears. The pthread_rwlock_context
71 is embedded in the thread context and contains a pointer to the
72 head of the list of lock info structures, as well as a count of
73 read locks that are untracked, because no info structure could be
74 allocated for them. */
75 struct _pthread_rwlock_t;
76 typedef struct _pthread_rwlock_info {
77 struct _pthread_rwlock_info *pr_next;
78 struct _pthread_rwlock_t *pr_lock;
79 int pr_lock_count;
80 } pthread_readlock_info;
83 /* We keep thread specific data in a special data structure, a two-level
84 array. The top-level array contains pointers to dynamically allocated
85 arrays of a certain number of data pointers. So we can implement a
86 sparse array. Each dynamic second-level array has
87 PTHREAD_KEY_2NDLEVEL_SIZE
88 entries. This value shouldn't be too large. */
89 #define PTHREAD_KEY_2NDLEVEL_SIZE 32
91 /* We need to address PTHREAD_KEYS_MAX key with PTHREAD_KEY_2NDLEVEL_SIZE
92 keys in each subarray. */
93 #define PTHREAD_KEY_1STLEVEL_SIZE \
94 ((PTHREAD_KEYS_MAX + PTHREAD_KEY_2NDLEVEL_SIZE - 1) \
95 / PTHREAD_KEY_2NDLEVEL_SIZE)
98 union dtv;
101 struct _pthread_descr_struct {
102 /* XXX Remove this union for IA-64 style TLS module */
103 union {
104 struct {
105 void *tcb; /* Pointer to the TCB. This is not always
106 the address of this thread descriptor. */
107 union dtv *dtvp;
108 pthread_descr self; /* Pointer to this structure */
109 } data;
110 void *__padding[16];
111 } p_header;
112 pthread_descr p_nextlive, p_prevlive;
113 /* Double chaining of active threads */
114 pthread_descr p_nextwaiting; /* Next element in the queue holding the thr */
115 pthread_descr p_nextlock; /* can be on a queue and waiting on a lock */
116 pthread_t p_tid; /* Thread identifier */
117 int p_pid; /* PID of Unix process */
118 int p_priority; /* Thread priority (== 0 if not realtime) */
119 struct _pthread_fastlock * p_lock; /* Spinlock for synchronized accesses */
120 int p_signal; /* last signal received */
121 sigjmp_buf * p_signal_jmp; /* where to siglongjmp on a signal or NULL */
122 sigjmp_buf * p_cancel_jmp; /* where to siglongjmp on a cancel or NULL */
123 char p_terminated; /* true if terminated e.g. by pthread_exit */
124 char p_detached; /* true if detached */
125 char p_exited; /* true if the assoc. process terminated */
126 void * p_retval; /* placeholder for return value */
127 int p_retcode; /* placeholder for return code */
128 pthread_descr p_joining; /* thread joining on that thread or NULL */
129 struct _pthread_cleanup_buffer * p_cleanup; /* cleanup functions */
130 char p_cancelstate; /* cancellation state */
131 char p_canceltype; /* cancellation type (deferred/async) */
132 char p_canceled; /* cancellation request pending */
133 char * p_in_sighandler; /* stack address of sighandler, or NULL */
134 char p_sigwaiting; /* true if a sigwait() is in progress */
135 struct pthread_start_args p_start_args; /* arguments for thread creation */
136 void ** p_specific[PTHREAD_KEY_1STLEVEL_SIZE]; /* thread-specific data */
137 #if !(USE_TLS && HAVE___THREAD)
138 void * p_libc_specific[_LIBC_TSD_KEY_N]; /* thread-specific data for libc */
139 int * p_errnop; /* pointer to used errno variable */
140 int p_errno; /* error returned by last system call */
141 int * p_h_errnop; /* pointer to used h_errno variable */
142 int p_h_errno; /* error returned by last netdb function */
143 struct __res_state *p_resp; /* Pointer to resolver state */
144 struct __res_state p_res; /* per-thread resolver state */
145 #endif
146 int p_userstack; /* nonzero if the user provided the stack */
147 void *p_guardaddr; /* address of guard area or NULL */
148 size_t p_guardsize; /* size of guard area */
149 int p_nr; /* Index of descriptor in __pthread_handles */
150 int p_report_events; /* Nonzero if events must be reported. */
151 td_eventbuf_t p_eventbuf; /* Data for event. */
152 struct pthread_atomic p_resume_count; /* number of times restart() was
153 called on thread */
154 char p_woken_by_cancel; /* cancellation performed wakeup */
155 char p_condvar_avail; /* flag if conditional variable became avail */
156 char p_sem_avail; /* flag if semaphore became available */
157 pthread_extricate_if *p_extricate; /* See above */
158 pthread_readlock_info *p_readlock_list; /* List of readlock info structs */
159 pthread_readlock_info *p_readlock_free; /* Free list of structs */
160 int p_untracked_readlock_count; /* Readlocks not tracked by list */
161 int p_inheritsched; /* copied from the thread attribute */
162 #if HP_TIMING_AVAIL
163 hp_timing_t p_cpuclock_offset; /* Initial CPU clock for thread. */
164 #endif
165 #ifdef USE_TLS
166 char *p_stackaddr; /* Stack address. */
167 #endif
168 /* New elements must be added at the end. */
169 } __attribute__ ((aligned(32))); /* We need to align the structure so that
170 doubles are aligned properly. This is 8
171 bytes on MIPS and 16 bytes on MIPS64.
172 32 bytes might give better cache
173 utilization. */
177 /* Limit between the stack of the initial thread (above) and the
178 stacks of other threads (below). Aligned on a STACK_SIZE boundary.
179 Initially 0, meaning that the current thread is (by definition)
180 the initial thread. */
182 extern char *__pthread_initial_thread_bos;
184 /* Descriptor of the initial thread */
186 extern struct _pthread_descr_struct __pthread_initial_thread;
188 /* Limits of the thread manager stack. */
190 extern char *__pthread_manager_thread_bos;
191 extern char *__pthread_manager_thread_tos;
193 /* Descriptor of the manager thread */
195 extern struct _pthread_descr_struct __pthread_manager_thread;
197 /* Indicate whether at least one thread has a user-defined stack (if 1),
198 or all threads have stacks supplied by LinuxThreads (if 0). */
200 extern int __pthread_nonstandard_stacks;
202 /* The max size of the thread stack segments. If the default
203 THREAD_SELF implementation is used, this must be a power of two and
204 a multiple of PAGE_SIZE. */
205 #ifndef STACK_SIZE
206 #define STACK_SIZE (2 * 1024 * 1024)
207 #endif
209 /* Get some notion of the current stack. Need not be exactly the top
210 of the stack, just something somewhere in the current frame. */
211 #ifndef CURRENT_STACK_FRAME
212 #define CURRENT_STACK_FRAME ({ char __csf; &__csf; })
213 #endif
215 /* Recover thread descriptor for the current thread */
217 extern pthread_descr __pthread_find_self (void) __attribute__ ((const));
219 static inline pthread_descr thread_self (void) __attribute__ ((const));
220 static inline pthread_descr thread_self (void)
222 #ifdef THREAD_SELF
223 return THREAD_SELF;
224 #else
225 char *sp = CURRENT_STACK_FRAME;
226 if (sp >= __pthread_initial_thread_bos)
227 return &__pthread_initial_thread;
228 else if (sp >= __pthread_manager_thread_bos
229 && sp < __pthread_manager_thread_tos)
230 return &__pthread_manager_thread;
231 else if (__pthread_nonstandard_stacks)
232 return __pthread_find_self();
233 else
234 #ifdef _STACK_GROWS_DOWN
235 return (pthread_descr)(((unsigned long)sp | (STACK_SIZE-1))+1) - 1;
236 #else
237 return (pthread_descr)((unsigned long)sp &~ (STACK_SIZE-1));
238 #endif
239 #endif
242 #endif /* descr.h */