Deleted Added
full compact
thr_private.h (213161) thr_private.h (213241)
1/*
2 * Copyright (C) 2005 Daniel M. Eischen <deischen@freebsd.org>
3 * Copyright (c) 2005 David Xu <davidxu@freebsd.org>
4 * Copyright (c) 1995-1998 John Birrell <jb@cimlogic.com.au>.
5 *
6 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 * 1. Redistributions of source code must retain the above copyright
12 * notice unmodified, this list of conditions, and the following
13 * disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 *
1/*
2 * Copyright (C) 2005 Daniel M. Eischen <deischen@freebsd.org>
3 * Copyright (c) 2005 David Xu <davidxu@freebsd.org>
4 * Copyright (c) 1995-1998 John Birrell <jb@cimlogic.com.au>.
5 *
6 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 * 1. Redistributions of source code must retain the above copyright
12 * notice unmodified, this list of conditions, and the following
13 * disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 *
29 * $FreeBSD: head/lib/libthr/thread/thr_private.h 213161 2010-09-25 08:36:46Z davidxu $
29 * $FreeBSD: head/lib/libthr/thread/thr_private.h 213241 2010-09-28 04:57:56Z davidxu $
30 */
31
32#ifndef _THR_PRIVATE_H
33#define _THR_PRIVATE_H
34
35/*
36 * Include files.
37 */
38#include <sys/types.h>
39#include <sys/time.h>
40#include <sys/cdefs.h>
41#include <sys/queue.h>
42#include <sys/param.h>
43#include <sys/cpuset.h>
44#include <machine/atomic.h>
45#include <errno.h>
46#include <limits.h>
47#include <signal.h>
48#include <stddef.h>
49#include <stdio.h>
50#include <unistd.h>
51#include <ucontext.h>
52#include <sys/thr.h>
53#include <pthread.h>
54
55#define SYM_FB10(sym) __CONCAT(sym, _fb10)
56#define SYM_FBP10(sym) __CONCAT(sym, _fbp10)
57#define WEAK_REF(sym, alias) __weak_reference(sym, alias)
58#define SYM_COMPAT(sym, impl, ver) __sym_compat(sym, impl, ver)
59#define SYM_DEFAULT(sym, impl, ver) __sym_default(sym, impl, ver)
60
61#define FB10_COMPAT(func, sym) \
62 WEAK_REF(func, SYM_FB10(sym)); \
63 SYM_COMPAT(sym, SYM_FB10(sym), FBSD_1.0)
64
65#define FB10_COMPAT_PRIVATE(func, sym) \
66 WEAK_REF(func, SYM_FBP10(sym)); \
67 SYM_DEFAULT(sym, SYM_FBP10(sym), FBSDprivate_1.0)
68
69#include "pthread_md.h"
70#include "thr_umtx.h"
71#include "thread_db.h"
72
73#ifdef _PTHREAD_FORCED_UNWIND
74#include <unwind-generic.h>
75#endif
76
77typedef TAILQ_HEAD(pthreadlist, pthread) pthreadlist;
78typedef TAILQ_HEAD(atfork_head, pthread_atfork) atfork_head;
79TAILQ_HEAD(mutex_queue, pthread_mutex);
80
81/* Signal to do cancellation */
82#define SIGCANCEL 32
83
84/*
85 * Kernel fatal error handler macro.
86 */
87#define PANIC(string) _thread_exit(__FILE__,__LINE__,string)
88
89/* Output debug messages like this: */
90#define stdout_debug(args...) _thread_printf(STDOUT_FILENO, ##args)
91#define stderr_debug(args...) _thread_printf(STDERR_FILENO, ##args)
92
93#ifdef _PTHREADS_INVARIANTS
94#define THR_ASSERT(cond, msg) do { \
95 if (__predict_false(!(cond))) \
96 PANIC(msg); \
97} while (0)
98#else
99#define THR_ASSERT(cond, msg)
100#endif
101
102#ifdef PIC
103# define STATIC_LIB_REQUIRE(name)
104#else
105# define STATIC_LIB_REQUIRE(name) __asm (".globl " #name)
106#endif
107
108#define TIMESPEC_ADD(dst, src, val) \
109 do { \
110 (dst)->tv_sec = (src)->tv_sec + (val)->tv_sec; \
111 (dst)->tv_nsec = (src)->tv_nsec + (val)->tv_nsec; \
112 if ((dst)->tv_nsec >= 1000000000) { \
113 (dst)->tv_sec++; \
114 (dst)->tv_nsec -= 1000000000; \
115 } \
116 } while (0)
117
118#define TIMESPEC_SUB(dst, src, val) \
119 do { \
120 (dst)->tv_sec = (src)->tv_sec - (val)->tv_sec; \
121 (dst)->tv_nsec = (src)->tv_nsec - (val)->tv_nsec; \
122 if ((dst)->tv_nsec < 0) { \
123 (dst)->tv_sec--; \
124 (dst)->tv_nsec += 1000000000; \
125 } \
126 } while (0)
127
30 */
31
32#ifndef _THR_PRIVATE_H
33#define _THR_PRIVATE_H
34
35/*
36 * Include files.
37 */
38#include <sys/types.h>
39#include <sys/time.h>
40#include <sys/cdefs.h>
41#include <sys/queue.h>
42#include <sys/param.h>
43#include <sys/cpuset.h>
44#include <machine/atomic.h>
45#include <errno.h>
46#include <limits.h>
47#include <signal.h>
48#include <stddef.h>
49#include <stdio.h>
50#include <unistd.h>
51#include <ucontext.h>
52#include <sys/thr.h>
53#include <pthread.h>
54
55#define SYM_FB10(sym) __CONCAT(sym, _fb10)
56#define SYM_FBP10(sym) __CONCAT(sym, _fbp10)
57#define WEAK_REF(sym, alias) __weak_reference(sym, alias)
58#define SYM_COMPAT(sym, impl, ver) __sym_compat(sym, impl, ver)
59#define SYM_DEFAULT(sym, impl, ver) __sym_default(sym, impl, ver)
60
61#define FB10_COMPAT(func, sym) \
62 WEAK_REF(func, SYM_FB10(sym)); \
63 SYM_COMPAT(sym, SYM_FB10(sym), FBSD_1.0)
64
65#define FB10_COMPAT_PRIVATE(func, sym) \
66 WEAK_REF(func, SYM_FBP10(sym)); \
67 SYM_DEFAULT(sym, SYM_FBP10(sym), FBSDprivate_1.0)
68
69#include "pthread_md.h"
70#include "thr_umtx.h"
71#include "thread_db.h"
72
73#ifdef _PTHREAD_FORCED_UNWIND
74#include <unwind-generic.h>
75#endif
76
77typedef TAILQ_HEAD(pthreadlist, pthread) pthreadlist;
78typedef TAILQ_HEAD(atfork_head, pthread_atfork) atfork_head;
79TAILQ_HEAD(mutex_queue, pthread_mutex);
80
81/* Signal to do cancellation */
82#define SIGCANCEL 32
83
84/*
85 * Kernel fatal error handler macro.
86 */
87#define PANIC(string) _thread_exit(__FILE__,__LINE__,string)
88
89/* Output debug messages like this: */
90#define stdout_debug(args...) _thread_printf(STDOUT_FILENO, ##args)
91#define stderr_debug(args...) _thread_printf(STDERR_FILENO, ##args)
92
93#ifdef _PTHREADS_INVARIANTS
94#define THR_ASSERT(cond, msg) do { \
95 if (__predict_false(!(cond))) \
96 PANIC(msg); \
97} while (0)
98#else
99#define THR_ASSERT(cond, msg)
100#endif
101
102#ifdef PIC
103# define STATIC_LIB_REQUIRE(name)
104#else
105# define STATIC_LIB_REQUIRE(name) __asm (".globl " #name)
106#endif
107
108#define TIMESPEC_ADD(dst, src, val) \
109 do { \
110 (dst)->tv_sec = (src)->tv_sec + (val)->tv_sec; \
111 (dst)->tv_nsec = (src)->tv_nsec + (val)->tv_nsec; \
112 if ((dst)->tv_nsec >= 1000000000) { \
113 (dst)->tv_sec++; \
114 (dst)->tv_nsec -= 1000000000; \
115 } \
116 } while (0)
117
118#define TIMESPEC_SUB(dst, src, val) \
119 do { \
120 (dst)->tv_sec = (src)->tv_sec - (val)->tv_sec; \
121 (dst)->tv_nsec = (src)->tv_nsec - (val)->tv_nsec; \
122 if ((dst)->tv_nsec < 0) { \
123 (dst)->tv_sec--; \
124 (dst)->tv_nsec += 1000000000; \
125 } \
126 } while (0)
127
128/* XXX These values should be same as those defined in pthread.h */
129#define THR_MUTEX_INITIALIZER ((struct pthread_mutex *)NULL)
130#define THR_ADAPTIVE_MUTEX_INITIALIZER ((struct pthread_mutex *)1)
131#define THR_MUTEX_DESTROYED ((struct pthread_mutex *)2)
132#define THR_COND_INITIALIZER ((struct pthread_cond *)NULL)
133#define THR_COND_DESTROYED ((struct pthread_cond *)1)
134#define THR_RWLOCK_INITIALIZER ((struct pthread_rwlock *)NULL)
135#define THR_RWLOCK_DESTROYED ((struct pthread_rwlock *)1)
136
128struct pthread_mutex {
129 /*
130 * Lock for accesses to this structure.
131 */
132 struct umutex m_lock;
133 enum pthread_mutextype m_type;
134 struct pthread *m_owner;
135 int m_count;
136 int m_refcount;
137 int m_spinloops;
138 int m_yieldloops;
139 int m_private;
140 /*
141 * Link for all mutexes a thread currently owns.
142 */
143 TAILQ_ENTRY(pthread_mutex) m_qe;
144};
145
146struct pthread_mutex_attr {
147 enum pthread_mutextype m_type;
148 int m_protocol;
149 int m_ceiling;
150};
151
152#define PTHREAD_MUTEXATTR_STATIC_INITIALIZER \
153 { PTHREAD_MUTEX_DEFAULT, PTHREAD_PRIO_NONE, 0, MUTEX_FLAGS_PRIVATE }
154
155struct pthread_cond {
156 struct umutex c_lock;
157 struct ucond c_kerncv;
158 int c_pshared;
159 int c_clockid;
160};
161
162struct pthread_cond_attr {
163 int c_pshared;
164 int c_clockid;
165};
166
167struct pthread_barrier {
168 struct umutex b_lock;
169 struct ucond b_cv;
170 volatile int64_t b_cycle;
171 volatile int b_count;
172 volatile int b_waiters;
173};
174
175struct pthread_barrierattr {
176 int pshared;
177};
178
179struct pthread_spinlock {
180 struct umutex s_lock;
181};
182
183/*
184 * Flags for condition variables.
185 */
186#define COND_FLAGS_PRIVATE 0x01
187#define COND_FLAGS_INITED 0x02
188#define COND_FLAGS_BUSY 0x04
189
190/*
191 * Cleanup definitions.
192 */
193struct pthread_cleanup {
194 struct pthread_cleanup *prev;
195 void (*routine)(void *);
196 void *routine_arg;
197 int onheap;
198};
199
200#define THR_CLEANUP_PUSH(td, func, arg) { \
201 struct pthread_cleanup __cup; \
202 \
203 __cup.routine = func; \
204 __cup.routine_arg = arg; \
205 __cup.onheap = 0; \
206 __cup.prev = (td)->cleanup; \
207 (td)->cleanup = &__cup;
208
209#define THR_CLEANUP_POP(td, exec) \
210 (td)->cleanup = __cup.prev; \
211 if ((exec) != 0) \
212 __cup.routine(__cup.routine_arg); \
213}
214
215struct pthread_atfork {
216 TAILQ_ENTRY(pthread_atfork) qe;
217 void (*prepare)(void);
218 void (*parent)(void);
219 void (*child)(void);
220};
221
222struct pthread_attr {
223 int sched_policy;
224 int sched_inherit;
225 int prio;
226 int suspend;
227#define THR_STACK_USER 0x100 /* 0xFF reserved for <pthread.h> */
228 int flags;
229 void *stackaddr_attr;
230 size_t stacksize_attr;
231 size_t guardsize_attr;
232 cpuset_t *cpuset;
233 size_t cpusetsize;
234};
235
236/*
237 * Thread creation state attributes.
238 */
239#define THR_CREATE_RUNNING 0
240#define THR_CREATE_SUSPENDED 1
241
242/*
243 * Miscellaneous definitions.
244 */
245#define THR_STACK_DEFAULT (sizeof(void *) / 4 * 1024 * 1024)
246
247/*
248 * Maximum size of initial thread's stack. This perhaps deserves to be larger
249 * than the stacks of other threads, since many applications are likely to run
250 * almost entirely on this stack.
251 */
252#define THR_STACK_INITIAL (THR_STACK_DEFAULT * 2)
253
254/*
255 * Define priorities returned by kernel.
256 */
257#define THR_MIN_PRIORITY (_thr_priorities[SCHED_OTHER-1].pri_min)
258#define THR_MAX_PRIORITY (_thr_priorities[SCHED_OTHER-1].pri_max)
259#define THR_DEF_PRIORITY (_thr_priorities[SCHED_OTHER-1].pri_default)
260
261#define THR_MIN_RR_PRIORITY (_thr_priorities[SCHED_RR-1].pri_min)
262#define THR_MAX_RR_PRIORITY (_thr_priorities[SCHED_RR-1].pri_max)
263#define THR_DEF_RR_PRIORITY (_thr_priorities[SCHED_RR-1].pri_default)
264
265/* XXX The SCHED_FIFO should have same priority range as SCHED_RR */
266#define THR_MIN_FIFO_PRIORITY (_thr_priorities[SCHED_FIFO_1].pri_min)
267#define THR_MAX_FIFO_PRIORITY (_thr_priorities[SCHED_FIFO-1].pri_max)
268#define THR_DEF_FIFO_PRIORITY (_thr_priorities[SCHED_FIFO-1].pri_default)
269
270struct pthread_prio {
271 int pri_min;
272 int pri_max;
273 int pri_default;
274};
275
276struct pthread_rwlockattr {
277 int pshared;
278};
279
280struct pthread_rwlock {
281 struct urwlock lock;
282 struct pthread *owner;
283};
284
285/*
286 * Thread states.
287 */
288enum pthread_state {
289 PS_RUNNING,
290 PS_DEAD
291};
292
293struct pthread_specific_elem {
294 const void *data;
295 int seqno;
296};
297
298struct pthread_key {
299 volatile int allocated;
300 int seqno;
301 void (*destructor)(void *);
302};
303
304/*
305 * lwpid_t is 32bit but kernel thr API exports tid as long type
306 * in very earily date.
307 */
308#define TID(thread) ((uint32_t) ((thread)->tid))
309
310/*
311 * Thread structure.
312 */
313struct pthread {
314 /* Kernel thread id. */
315 long tid;
316#define TID_TERMINATED 1
317
318 /*
319 * Lock for accesses to this thread structure.
320 */
321 struct umutex lock;
322
323 /* Internal condition variable cycle number. */
324 uint32_t cycle;
325
326 /* How many low level locks the thread held. */
327 int locklevel;
328
329 /*
330 * Set to non-zero when this thread has entered a critical
331 * region. We allow for recursive entries into critical regions.
332 */
333 int critical_count;
334
335 /* Signal blocked counter. */
336 int sigblock;
337
338 /* Queue entry for list of all threads. */
339 TAILQ_ENTRY(pthread) tle; /* link for all threads in process */
340
341 /* Queue entry for GC lists. */
342 TAILQ_ENTRY(pthread) gcle;
343
344 /* Hash queue entry. */
345 LIST_ENTRY(pthread) hle;
346
347 /* Threads reference count. */
348 int refcount;
349
350 /*
351 * Thread start routine, argument, stack pointer and thread
352 * attributes.
353 */
354 void *(*start_routine)(void *);
355 void *arg;
356 struct pthread_attr attr;
357
358#define SHOULD_CANCEL(thr) \
359 ((thr)->cancel_pending && (thr)->cancel_enable && \
360 (thr)->no_cancel == 0)
361
362 /* Cancellation is enabled */
363 int cancel_enable;
364
365 /* Cancellation request is pending */
366 int cancel_pending;
367
368 /* Thread is at cancellation point */
369 int cancel_point;
370
371 /* Cancellation is temporarily disabled */
372 int no_cancel;
373
374 /* Asynchronouse cancellation is enabled */
375 int cancel_async;
376
377 /* Cancellation is in progress */
378 int cancelling;
379
380 /* Thread temporary signal mask. */
381 sigset_t sigmask;
382
383 /* Thread should unblock SIGCANCEL. */
384 int unblock_sigcancel;
385
386 /* In sigsuspend state */
387 int in_sigsuspend;
388
389 /* deferred signal info */
390 siginfo_t deferred_siginfo;
391
392 /* signal mask to restore. */
393 sigset_t deferred_sigmask;
394
395 /* the sigaction should be used for deferred signal. */
396 struct sigaction deferred_sigact;
397
398 /* Force new thread to exit. */
399 int force_exit;
400
401 /* Thread state: */
402 enum pthread_state state;
403
404 /*
405 * Error variable used instead of errno. The function __error()
406 * returns a pointer to this.
407 */
408 int error;
409
410 /*
411 * The joiner is the thread that is joining to this thread. The
412 * join status keeps track of a join operation to another thread.
413 */
414 struct pthread *joiner;
415
416 /* Miscellaneous flags; only set with scheduling lock held. */
417 int flags;
418#define THR_FLAGS_PRIVATE 0x0001
419#define THR_FLAGS_NEED_SUSPEND 0x0002 /* thread should be suspended */
420#define THR_FLAGS_SUSPENDED 0x0004 /* thread is suspended */
421#define THR_FLAGS_DETACHED 0x0008 /* thread is detached */
422
423 /* Thread list flags; only set with thread list lock held. */
424 int tlflags;
425#define TLFLAGS_GC_SAFE 0x0001 /* thread safe for cleaning */
426#define TLFLAGS_IN_TDLIST 0x0002 /* thread in all thread list */
427#define TLFLAGS_IN_GCLIST 0x0004 /* thread in gc list */
428
429 /* Queue of currently owned NORMAL or PRIO_INHERIT type mutexes. */
430 struct mutex_queue mutexq;
431
432 /* Queue of all owned PRIO_PROTECT mutexes. */
433 struct mutex_queue pp_mutexq;
434
435 void *ret;
436 struct pthread_specific_elem *specific;
437 int specific_data_count;
438
439 /* Number rwlocks rdlocks held. */
440 int rdlock_count;
441
442 /*
443 * Current locks bitmap for rtld. */
444 int rtld_bits;
445
446 /* Thread control block */
447 struct tcb *tcb;
448
449 /* Cleanup handlers Link List */
450 struct pthread_cleanup *cleanup;
451
452#ifdef _PTHREAD_FORCED_UNWIND
453 struct _Unwind_Exception ex;
454 void *unwind_stackend;
455 int unwind_disabled;
456#endif
457
458 /*
459 * Magic value to help recognize a valid thread structure
460 * from an invalid one:
461 */
462#define THR_MAGIC ((u_int32_t) 0xd09ba115)
463 u_int32_t magic;
464
465 /* Enable event reporting */
466 int report_events;
467
468 /* Event mask */
469 int event_mask;
470
471 /* Event */
472 td_event_msg_t event_buf;
473};
474
475#define THR_SHOULD_GC(thrd) \
476 ((thrd)->refcount == 0 && (thrd)->state == PS_DEAD && \
477 ((thrd)->flags & THR_FLAGS_DETACHED) != 0)
478
479#define THR_IN_CRITICAL(thrd) \
480 (((thrd)->locklevel > 0) || \
481 ((thrd)->critical_count > 0))
482
483#define THR_CRITICAL_ENTER(thrd) \
484 (thrd)->critical_count++
485
486#define THR_CRITICAL_LEAVE(thrd) \
487 do { \
488 (thrd)->critical_count--; \
489 _thr_ast(thrd); \
490 } while (0)
491
492#define THR_UMUTEX_TRYLOCK(thrd, lck) \
493 _thr_umutex_trylock((lck), TID(thrd))
494
495#define THR_UMUTEX_LOCK(thrd, lck) \
496 _thr_umutex_lock((lck), TID(thrd))
497
498#define THR_UMUTEX_TIMEDLOCK(thrd, lck, timo) \
499 _thr_umutex_timedlock((lck), TID(thrd), (timo))
500
501#define THR_UMUTEX_UNLOCK(thrd, lck) \
502 _thr_umutex_unlock((lck), TID(thrd))
503
504#define THR_LOCK_ACQUIRE(thrd, lck) \
505do { \
506 (thrd)->locklevel++; \
507 _thr_umutex_lock(lck, TID(thrd)); \
508} while (0)
509
510#ifdef _PTHREADS_INVARIANTS
511#define THR_ASSERT_LOCKLEVEL(thrd) \
512do { \
513 if (__predict_false((thrd)->locklevel <= 0)) \
514 _thr_assert_lock_level(); \
515} while (0)
516#else
517#define THR_ASSERT_LOCKLEVEL(thrd)
518#endif
519
520#define THR_LOCK_RELEASE(thrd, lck) \
521do { \
522 THR_ASSERT_LOCKLEVEL(thrd); \
523 _thr_umutex_unlock((lck), TID(thrd)); \
524 (thrd)->locklevel--; \
525 _thr_ast(thrd); \
526} while (0)
527
528#define THR_LOCK(curthrd) THR_LOCK_ACQUIRE(curthrd, &(curthrd)->lock)
529#define THR_UNLOCK(curthrd) THR_LOCK_RELEASE(curthrd, &(curthrd)->lock)
530#define THR_THREAD_LOCK(curthrd, thr) THR_LOCK_ACQUIRE(curthrd, &(thr)->lock)
531#define THR_THREAD_UNLOCK(curthrd, thr) THR_LOCK_RELEASE(curthrd, &(thr)->lock)
532
533#define THREAD_LIST_RDLOCK(curthrd) \
534do { \
535 (curthrd)->locklevel++; \
536 _thr_rwl_rdlock(&_thr_list_lock); \
537} while (0)
538
539#define THREAD_LIST_WRLOCK(curthrd) \
540do { \
541 (curthrd)->locklevel++; \
542 _thr_rwl_wrlock(&_thr_list_lock); \
543} while (0)
544
545#define THREAD_LIST_UNLOCK(curthrd) \
546do { \
547 _thr_rwl_unlock(&_thr_list_lock); \
548 (curthrd)->locklevel--; \
549 _thr_ast(curthrd); \
550} while (0)
551
552/*
553 * Macros to insert/remove threads to the all thread list and
554 * the gc list.
555 */
556#define THR_LIST_ADD(thrd) do { \
557 if (((thrd)->tlflags & TLFLAGS_IN_TDLIST) == 0) { \
558 TAILQ_INSERT_HEAD(&_thread_list, thrd, tle); \
559 _thr_hash_add(thrd); \
560 (thrd)->tlflags |= TLFLAGS_IN_TDLIST; \
561 } \
562} while (0)
563#define THR_LIST_REMOVE(thrd) do { \
564 if (((thrd)->tlflags & TLFLAGS_IN_TDLIST) != 0) { \
565 TAILQ_REMOVE(&_thread_list, thrd, tle); \
566 _thr_hash_remove(thrd); \
567 (thrd)->tlflags &= ~TLFLAGS_IN_TDLIST; \
568 } \
569} while (0)
570#define THR_GCLIST_ADD(thrd) do { \
571 if (((thrd)->tlflags & TLFLAGS_IN_GCLIST) == 0) { \
572 TAILQ_INSERT_HEAD(&_thread_gc_list, thrd, gcle);\
573 (thrd)->tlflags |= TLFLAGS_IN_GCLIST; \
574 _gc_count++; \
575 } \
576} while (0)
577#define THR_GCLIST_REMOVE(thrd) do { \
578 if (((thrd)->tlflags & TLFLAGS_IN_GCLIST) != 0) { \
579 TAILQ_REMOVE(&_thread_gc_list, thrd, gcle); \
580 (thrd)->tlflags &= ~TLFLAGS_IN_GCLIST; \
581 _gc_count--; \
582 } \
583} while (0)
584
585#define THR_REF_ADD(curthread, pthread) { \
586 THR_CRITICAL_ENTER(curthread); \
587 pthread->refcount++; \
588} while (0)
589
590#define THR_REF_DEL(curthread, pthread) { \
591 pthread->refcount--; \
592 THR_CRITICAL_LEAVE(curthread); \
593} while (0)
594
595#define GC_NEEDED() (_gc_count >= 5)
596
597#define SHOULD_REPORT_EVENT(curthr, e) \
598 (curthr->report_events && \
599 (((curthr)->event_mask | _thread_event_mask ) & e) != 0)
600
601extern int __isthreaded;
602
603/*
604 * Global variables for the pthread kernel.
605 */
606
607extern char *_usrstack __hidden;
608extern struct pthread *_thr_initial __hidden;
609
610/* For debugger */
611extern int _libthr_debug;
612extern int _thread_event_mask;
613extern struct pthread *_thread_last_event;
614
615/* List of all threads: */
616extern pthreadlist _thread_list;
617
618/* List of threads needing GC: */
619extern pthreadlist _thread_gc_list __hidden;
620
621extern int _thread_active_threads;
622extern atfork_head _thr_atfork_list __hidden;
623extern struct urwlock _thr_atfork_lock __hidden;
624
625/* Default thread attributes: */
626extern struct pthread_attr _pthread_attr_default __hidden;
627
628/* Default mutex attributes: */
629extern struct pthread_mutex_attr _pthread_mutexattr_default __hidden;
137struct pthread_mutex {
138 /*
139 * Lock for accesses to this structure.
140 */
141 struct umutex m_lock;
142 enum pthread_mutextype m_type;
143 struct pthread *m_owner;
144 int m_count;
145 int m_refcount;
146 int m_spinloops;
147 int m_yieldloops;
148 int m_private;
149 /*
150 * Link for all mutexes a thread currently owns.
151 */
152 TAILQ_ENTRY(pthread_mutex) m_qe;
153};
154
155struct pthread_mutex_attr {
156 enum pthread_mutextype m_type;
157 int m_protocol;
158 int m_ceiling;
159};
160
161#define PTHREAD_MUTEXATTR_STATIC_INITIALIZER \
162 { PTHREAD_MUTEX_DEFAULT, PTHREAD_PRIO_NONE, 0, MUTEX_FLAGS_PRIVATE }
163
164struct pthread_cond {
165 struct umutex c_lock;
166 struct ucond c_kerncv;
167 int c_pshared;
168 int c_clockid;
169};
170
171struct pthread_cond_attr {
172 int c_pshared;
173 int c_clockid;
174};
175
176struct pthread_barrier {
177 struct umutex b_lock;
178 struct ucond b_cv;
179 volatile int64_t b_cycle;
180 volatile int b_count;
181 volatile int b_waiters;
182};
183
184struct pthread_barrierattr {
185 int pshared;
186};
187
188struct pthread_spinlock {
189 struct umutex s_lock;
190};
191
192/*
193 * Flags for condition variables.
194 */
195#define COND_FLAGS_PRIVATE 0x01
196#define COND_FLAGS_INITED 0x02
197#define COND_FLAGS_BUSY 0x04
198
199/*
200 * Cleanup definitions.
201 */
202struct pthread_cleanup {
203 struct pthread_cleanup *prev;
204 void (*routine)(void *);
205 void *routine_arg;
206 int onheap;
207};
208
209#define THR_CLEANUP_PUSH(td, func, arg) { \
210 struct pthread_cleanup __cup; \
211 \
212 __cup.routine = func; \
213 __cup.routine_arg = arg; \
214 __cup.onheap = 0; \
215 __cup.prev = (td)->cleanup; \
216 (td)->cleanup = &__cup;
217
218#define THR_CLEANUP_POP(td, exec) \
219 (td)->cleanup = __cup.prev; \
220 if ((exec) != 0) \
221 __cup.routine(__cup.routine_arg); \
222}
223
224struct pthread_atfork {
225 TAILQ_ENTRY(pthread_atfork) qe;
226 void (*prepare)(void);
227 void (*parent)(void);
228 void (*child)(void);
229};
230
231struct pthread_attr {
232 int sched_policy;
233 int sched_inherit;
234 int prio;
235 int suspend;
236#define THR_STACK_USER 0x100 /* 0xFF reserved for <pthread.h> */
237 int flags;
238 void *stackaddr_attr;
239 size_t stacksize_attr;
240 size_t guardsize_attr;
241 cpuset_t *cpuset;
242 size_t cpusetsize;
243};
244
245/*
246 * Thread creation state attributes.
247 */
248#define THR_CREATE_RUNNING 0
249#define THR_CREATE_SUSPENDED 1
250
251/*
252 * Miscellaneous definitions.
253 */
254#define THR_STACK_DEFAULT (sizeof(void *) / 4 * 1024 * 1024)
255
256/*
257 * Maximum size of initial thread's stack. This perhaps deserves to be larger
258 * than the stacks of other threads, since many applications are likely to run
259 * almost entirely on this stack.
260 */
261#define THR_STACK_INITIAL (THR_STACK_DEFAULT * 2)
262
263/*
264 * Define priorities returned by kernel.
265 */
266#define THR_MIN_PRIORITY (_thr_priorities[SCHED_OTHER-1].pri_min)
267#define THR_MAX_PRIORITY (_thr_priorities[SCHED_OTHER-1].pri_max)
268#define THR_DEF_PRIORITY (_thr_priorities[SCHED_OTHER-1].pri_default)
269
270#define THR_MIN_RR_PRIORITY (_thr_priorities[SCHED_RR-1].pri_min)
271#define THR_MAX_RR_PRIORITY (_thr_priorities[SCHED_RR-1].pri_max)
272#define THR_DEF_RR_PRIORITY (_thr_priorities[SCHED_RR-1].pri_default)
273
274/* XXX The SCHED_FIFO should have same priority range as SCHED_RR */
275#define THR_MIN_FIFO_PRIORITY (_thr_priorities[SCHED_FIFO_1].pri_min)
276#define THR_MAX_FIFO_PRIORITY (_thr_priorities[SCHED_FIFO-1].pri_max)
277#define THR_DEF_FIFO_PRIORITY (_thr_priorities[SCHED_FIFO-1].pri_default)
278
279struct pthread_prio {
280 int pri_min;
281 int pri_max;
282 int pri_default;
283};
284
285struct pthread_rwlockattr {
286 int pshared;
287};
288
289struct pthread_rwlock {
290 struct urwlock lock;
291 struct pthread *owner;
292};
293
294/*
295 * Thread states.
296 */
297enum pthread_state {
298 PS_RUNNING,
299 PS_DEAD
300};
301
302struct pthread_specific_elem {
303 const void *data;
304 int seqno;
305};
306
307struct pthread_key {
308 volatile int allocated;
309 int seqno;
310 void (*destructor)(void *);
311};
312
313/*
314 * lwpid_t is 32bit but kernel thr API exports tid as long type
315 * in very earily date.
316 */
317#define TID(thread) ((uint32_t) ((thread)->tid))
318
319/*
320 * Thread structure.
321 */
322struct pthread {
323 /* Kernel thread id. */
324 long tid;
325#define TID_TERMINATED 1
326
327 /*
328 * Lock for accesses to this thread structure.
329 */
330 struct umutex lock;
331
332 /* Internal condition variable cycle number. */
333 uint32_t cycle;
334
335 /* How many low level locks the thread held. */
336 int locklevel;
337
338 /*
339 * Set to non-zero when this thread has entered a critical
340 * region. We allow for recursive entries into critical regions.
341 */
342 int critical_count;
343
344 /* Signal blocked counter. */
345 int sigblock;
346
347 /* Queue entry for list of all threads. */
348 TAILQ_ENTRY(pthread) tle; /* link for all threads in process */
349
350 /* Queue entry for GC lists. */
351 TAILQ_ENTRY(pthread) gcle;
352
353 /* Hash queue entry. */
354 LIST_ENTRY(pthread) hle;
355
356 /* Threads reference count. */
357 int refcount;
358
359 /*
360 * Thread start routine, argument, stack pointer and thread
361 * attributes.
362 */
363 void *(*start_routine)(void *);
364 void *arg;
365 struct pthread_attr attr;
366
367#define SHOULD_CANCEL(thr) \
368 ((thr)->cancel_pending && (thr)->cancel_enable && \
369 (thr)->no_cancel == 0)
370
371 /* Cancellation is enabled */
372 int cancel_enable;
373
374 /* Cancellation request is pending */
375 int cancel_pending;
376
377 /* Thread is at cancellation point */
378 int cancel_point;
379
380 /* Cancellation is temporarily disabled */
381 int no_cancel;
382
383 /* Asynchronouse cancellation is enabled */
384 int cancel_async;
385
386 /* Cancellation is in progress */
387 int cancelling;
388
389 /* Thread temporary signal mask. */
390 sigset_t sigmask;
391
392 /* Thread should unblock SIGCANCEL. */
393 int unblock_sigcancel;
394
395 /* In sigsuspend state */
396 int in_sigsuspend;
397
398 /* deferred signal info */
399 siginfo_t deferred_siginfo;
400
401 /* signal mask to restore. */
402 sigset_t deferred_sigmask;
403
404 /* the sigaction should be used for deferred signal. */
405 struct sigaction deferred_sigact;
406
407 /* Force new thread to exit. */
408 int force_exit;
409
410 /* Thread state: */
411 enum pthread_state state;
412
413 /*
414 * Error variable used instead of errno. The function __error()
415 * returns a pointer to this.
416 */
417 int error;
418
419 /*
420 * The joiner is the thread that is joining to this thread. The
421 * join status keeps track of a join operation to another thread.
422 */
423 struct pthread *joiner;
424
425 /* Miscellaneous flags; only set with scheduling lock held. */
426 int flags;
427#define THR_FLAGS_PRIVATE 0x0001
428#define THR_FLAGS_NEED_SUSPEND 0x0002 /* thread should be suspended */
429#define THR_FLAGS_SUSPENDED 0x0004 /* thread is suspended */
430#define THR_FLAGS_DETACHED 0x0008 /* thread is detached */
431
432 /* Thread list flags; only set with thread list lock held. */
433 int tlflags;
434#define TLFLAGS_GC_SAFE 0x0001 /* thread safe for cleaning */
435#define TLFLAGS_IN_TDLIST 0x0002 /* thread in all thread list */
436#define TLFLAGS_IN_GCLIST 0x0004 /* thread in gc list */
437
438 /* Queue of currently owned NORMAL or PRIO_INHERIT type mutexes. */
439 struct mutex_queue mutexq;
440
441 /* Queue of all owned PRIO_PROTECT mutexes. */
442 struct mutex_queue pp_mutexq;
443
444 void *ret;
445 struct pthread_specific_elem *specific;
446 int specific_data_count;
447
448 /* Number rwlocks rdlocks held. */
449 int rdlock_count;
450
451 /*
452 * Current locks bitmap for rtld. */
453 int rtld_bits;
454
455 /* Thread control block */
456 struct tcb *tcb;
457
458 /* Cleanup handlers Link List */
459 struct pthread_cleanup *cleanup;
460
461#ifdef _PTHREAD_FORCED_UNWIND
462 struct _Unwind_Exception ex;
463 void *unwind_stackend;
464 int unwind_disabled;
465#endif
466
467 /*
468 * Magic value to help recognize a valid thread structure
469 * from an invalid one:
470 */
471#define THR_MAGIC ((u_int32_t) 0xd09ba115)
472 u_int32_t magic;
473
474 /* Enable event reporting */
475 int report_events;
476
477 /* Event mask */
478 int event_mask;
479
480 /* Event */
481 td_event_msg_t event_buf;
482};
483
484#define THR_SHOULD_GC(thrd) \
485 ((thrd)->refcount == 0 && (thrd)->state == PS_DEAD && \
486 ((thrd)->flags & THR_FLAGS_DETACHED) != 0)
487
488#define THR_IN_CRITICAL(thrd) \
489 (((thrd)->locklevel > 0) || \
490 ((thrd)->critical_count > 0))
491
492#define THR_CRITICAL_ENTER(thrd) \
493 (thrd)->critical_count++
494
495#define THR_CRITICAL_LEAVE(thrd) \
496 do { \
497 (thrd)->critical_count--; \
498 _thr_ast(thrd); \
499 } while (0)
500
501#define THR_UMUTEX_TRYLOCK(thrd, lck) \
502 _thr_umutex_trylock((lck), TID(thrd))
503
504#define THR_UMUTEX_LOCK(thrd, lck) \
505 _thr_umutex_lock((lck), TID(thrd))
506
507#define THR_UMUTEX_TIMEDLOCK(thrd, lck, timo) \
508 _thr_umutex_timedlock((lck), TID(thrd), (timo))
509
510#define THR_UMUTEX_UNLOCK(thrd, lck) \
511 _thr_umutex_unlock((lck), TID(thrd))
512
513#define THR_LOCK_ACQUIRE(thrd, lck) \
514do { \
515 (thrd)->locklevel++; \
516 _thr_umutex_lock(lck, TID(thrd)); \
517} while (0)
518
519#ifdef _PTHREADS_INVARIANTS
520#define THR_ASSERT_LOCKLEVEL(thrd) \
521do { \
522 if (__predict_false((thrd)->locklevel <= 0)) \
523 _thr_assert_lock_level(); \
524} while (0)
525#else
526#define THR_ASSERT_LOCKLEVEL(thrd)
527#endif
528
529#define THR_LOCK_RELEASE(thrd, lck) \
530do { \
531 THR_ASSERT_LOCKLEVEL(thrd); \
532 _thr_umutex_unlock((lck), TID(thrd)); \
533 (thrd)->locklevel--; \
534 _thr_ast(thrd); \
535} while (0)
536
537#define THR_LOCK(curthrd) THR_LOCK_ACQUIRE(curthrd, &(curthrd)->lock)
538#define THR_UNLOCK(curthrd) THR_LOCK_RELEASE(curthrd, &(curthrd)->lock)
539#define THR_THREAD_LOCK(curthrd, thr) THR_LOCK_ACQUIRE(curthrd, &(thr)->lock)
540#define THR_THREAD_UNLOCK(curthrd, thr) THR_LOCK_RELEASE(curthrd, &(thr)->lock)
541
542#define THREAD_LIST_RDLOCK(curthrd) \
543do { \
544 (curthrd)->locklevel++; \
545 _thr_rwl_rdlock(&_thr_list_lock); \
546} while (0)
547
548#define THREAD_LIST_WRLOCK(curthrd) \
549do { \
550 (curthrd)->locklevel++; \
551 _thr_rwl_wrlock(&_thr_list_lock); \
552} while (0)
553
554#define THREAD_LIST_UNLOCK(curthrd) \
555do { \
556 _thr_rwl_unlock(&_thr_list_lock); \
557 (curthrd)->locklevel--; \
558 _thr_ast(curthrd); \
559} while (0)
560
561/*
562 * Macros to insert/remove threads to the all thread list and
563 * the gc list.
564 */
565#define THR_LIST_ADD(thrd) do { \
566 if (((thrd)->tlflags & TLFLAGS_IN_TDLIST) == 0) { \
567 TAILQ_INSERT_HEAD(&_thread_list, thrd, tle); \
568 _thr_hash_add(thrd); \
569 (thrd)->tlflags |= TLFLAGS_IN_TDLIST; \
570 } \
571} while (0)
572#define THR_LIST_REMOVE(thrd) do { \
573 if (((thrd)->tlflags & TLFLAGS_IN_TDLIST) != 0) { \
574 TAILQ_REMOVE(&_thread_list, thrd, tle); \
575 _thr_hash_remove(thrd); \
576 (thrd)->tlflags &= ~TLFLAGS_IN_TDLIST; \
577 } \
578} while (0)
579#define THR_GCLIST_ADD(thrd) do { \
580 if (((thrd)->tlflags & TLFLAGS_IN_GCLIST) == 0) { \
581 TAILQ_INSERT_HEAD(&_thread_gc_list, thrd, gcle);\
582 (thrd)->tlflags |= TLFLAGS_IN_GCLIST; \
583 _gc_count++; \
584 } \
585} while (0)
586#define THR_GCLIST_REMOVE(thrd) do { \
587 if (((thrd)->tlflags & TLFLAGS_IN_GCLIST) != 0) { \
588 TAILQ_REMOVE(&_thread_gc_list, thrd, gcle); \
589 (thrd)->tlflags &= ~TLFLAGS_IN_GCLIST; \
590 _gc_count--; \
591 } \
592} while (0)
593
594#define THR_REF_ADD(curthread, pthread) { \
595 THR_CRITICAL_ENTER(curthread); \
596 pthread->refcount++; \
597} while (0)
598
599#define THR_REF_DEL(curthread, pthread) { \
600 pthread->refcount--; \
601 THR_CRITICAL_LEAVE(curthread); \
602} while (0)
603
604#define GC_NEEDED() (_gc_count >= 5)
605
606#define SHOULD_REPORT_EVENT(curthr, e) \
607 (curthr->report_events && \
608 (((curthr)->event_mask | _thread_event_mask ) & e) != 0)
609
610extern int __isthreaded;
611
612/*
613 * Global variables for the pthread kernel.
614 */
615
616extern char *_usrstack __hidden;
617extern struct pthread *_thr_initial __hidden;
618
619/* For debugger */
620extern int _libthr_debug;
621extern int _thread_event_mask;
622extern struct pthread *_thread_last_event;
623
624/* List of all threads: */
625extern pthreadlist _thread_list;
626
627/* List of threads needing GC: */
628extern pthreadlist _thread_gc_list __hidden;
629
630extern int _thread_active_threads;
631extern atfork_head _thr_atfork_list __hidden;
632extern struct urwlock _thr_atfork_lock __hidden;
633
634/* Default thread attributes: */
635extern struct pthread_attr _pthread_attr_default __hidden;
636
637/* Default mutex attributes: */
638extern struct pthread_mutex_attr _pthread_mutexattr_default __hidden;
639extern struct pthread_mutex_attr _pthread_mutexattr_adaptive_default __hidden;
630
631/* Default condition variable attributes: */
632extern struct pthread_cond_attr _pthread_condattr_default __hidden;
633
634extern struct pthread_prio _thr_priorities[] __hidden;
635
636extern pid_t _thr_pid __hidden;
637extern int _thr_is_smp __hidden;
638
639extern size_t _thr_guard_default __hidden;
640extern size_t _thr_stack_default __hidden;
641extern size_t _thr_stack_initial __hidden;
642extern int _thr_page_size __hidden;
643extern int _thr_spinloops __hidden;
644extern int _thr_yieldloops __hidden;
645
646/* Garbage thread count. */
647extern int _gc_count __hidden;
648
649extern struct umutex _mutex_static_lock __hidden;
650extern struct umutex _cond_static_lock __hidden;
651extern struct umutex _rwlock_static_lock __hidden;
652extern struct umutex _keytable_lock __hidden;
653extern struct urwlock _thr_list_lock __hidden;
654extern struct umutex _thr_event_lock __hidden;
655
656/*
657 * Function prototype definitions.
658 */
659__BEGIN_DECLS
660int _thr_setthreaded(int) __hidden;
661int _mutex_cv_lock(pthread_mutex_t *, int count) __hidden;
662int _mutex_cv_unlock(pthread_mutex_t *, int *count) __hidden;
663int _mutex_reinit(pthread_mutex_t *) __hidden;
664void _mutex_fork(struct pthread *curthread) __hidden;
665void _libpthread_init(struct pthread *) __hidden;
666struct pthread *_thr_alloc(struct pthread *) __hidden;
667void _thread_exit(const char *, int, const char *) __hidden __dead2;
668int _thr_ref_add(struct pthread *, struct pthread *, int) __hidden;
669void _thr_ref_delete(struct pthread *, struct pthread *) __hidden;
670void _thr_ref_delete_unlocked(struct pthread *, struct pthread *) __hidden;
671int _thr_find_thread(struct pthread *, struct pthread *, int) __hidden;
672void _thr_rtld_init(void) __hidden;
673void _thr_rtld_fini(void) __hidden;
674void _thr_rtld_postfork_child(void) __hidden;
675int _thr_stack_alloc(struct pthread_attr *) __hidden;
676void _thr_stack_free(struct pthread_attr *) __hidden;
677void _thr_free(struct pthread *, struct pthread *) __hidden;
678void _thr_gc(struct pthread *) __hidden;
679void _thread_cleanupspecific(void) __hidden;
680void _thread_printf(int, const char *, ...) __hidden;
681void _thr_spinlock_init(void) __hidden;
682void _thr_cancel_enter(struct pthread *) __hidden;
683void _thr_cancel_enter2(struct pthread *, int) __hidden;
684void _thr_cancel_leave(struct pthread *, int) __hidden;
685void _thr_testcancel(struct pthread *) __hidden;
686void _thr_signal_block(struct pthread *) __hidden;
687void _thr_signal_unblock(struct pthread *) __hidden;
688void _thr_signal_init(void) __hidden;
689void _thr_signal_deinit(void) __hidden;
690int _thr_send_sig(struct pthread *, int sig) __hidden;
691void _thr_list_init(void) __hidden;
692void _thr_hash_add(struct pthread *) __hidden;
693void _thr_hash_remove(struct pthread *) __hidden;
694struct pthread *_thr_hash_find(struct pthread *) __hidden;
695void _thr_link(struct pthread *, struct pthread *) __hidden;
696void _thr_unlink(struct pthread *, struct pthread *) __hidden;
697void _thr_assert_lock_level(void) __hidden __dead2;
698void _thr_ast(struct pthread *) __hidden;
699void _thr_once_init(void) __hidden;
700void _thr_report_creation(struct pthread *curthread,
701 struct pthread *newthread) __hidden;
702void _thr_report_death(struct pthread *curthread) __hidden;
703int _thr_getscheduler(lwpid_t, int *, struct sched_param *) __hidden;
704int _thr_setscheduler(lwpid_t, int, const struct sched_param *) __hidden;
705void _thr_signal_prefork(void) __hidden;
706void _thr_signal_postfork(void) __hidden;
707void _thr_signal_postfork_child(void) __hidden;
708void _thr_try_gc(struct pthread *, struct pthread *) __hidden;
709int _rtp_to_schedparam(const struct rtprio *rtp, int *policy,
710 struct sched_param *param) __hidden;
711int _schedparam_to_rtp(int policy, const struct sched_param *param,
712 struct rtprio *rtp) __hidden;
713void _thread_bp_create(void);
714void _thread_bp_death(void);
715int _sched_yield(void);
716
717void _pthread_cleanup_push(void (*)(void *), void *);
718void _pthread_cleanup_pop(int);
719void _pthread_exit_mask(void *status, sigset_t *mask) __dead2 __hidden;
720void _pthread_cancel_enter(int maycancel);
721void _pthread_cancel_leave(int maycancel);
722
723/* #include <fcntl.h> */
724#ifdef _SYS_FCNTL_H_
725int __sys_fcntl(int, int, ...);
726int __sys_open(const char *, int, ...);
727int __sys_openat(int, const char *, int, ...);
728#endif
729
730/* #include <signal.h> */
731#ifdef _SIGNAL_H_
732int __sys_kill(pid_t, int);
733int __sys_sigaction(int, const struct sigaction *, struct sigaction *);
734int __sys_sigpending(sigset_t *);
735int __sys_sigprocmask(int, const sigset_t *, sigset_t *);
736int __sys_sigsuspend(const sigset_t *);
737int __sys_sigreturn(const ucontext_t *);
738int __sys_sigaltstack(const struct sigaltstack *, struct sigaltstack *);
739int __sys_sigwait(const sigset_t *, int *);
740int __sys_sigtimedwait(const sigset_t *, siginfo_t *,
741 const struct timespec *);
742int __sys_sigwaitinfo(const sigset_t *set, siginfo_t *info);
743#endif
744
745/* #include <time.h> */
746#ifdef _TIME_H_
747int __sys_nanosleep(const struct timespec *, struct timespec *);
748#endif
749
750/* #include <sys/ucontext.h> */
751#ifdef _SYS_UCONTEXT_H_
752int __sys_setcontext(const ucontext_t *ucp);
753int __sys_swapcontext(ucontext_t *oucp, const ucontext_t *ucp);
754#endif
755
756/* #include <unistd.h> */
757#ifdef _UNISTD_H_
758int __sys_close(int);
759int __sys_fork(void);
760pid_t __sys_getpid(void);
761ssize_t __sys_read(int, void *, size_t);
762ssize_t __sys_write(int, const void *, size_t);
763void __sys_exit(int);
764#endif
765
766int _umtx_op_err(void *, int op, u_long, void *, void *) __hidden;
767
768static inline int
769_thr_isthreaded(void)
770{
771 return (__isthreaded != 0);
772}
773
774static inline int
775_thr_is_inited(void)
776{
777 return (_thr_initial != NULL);
778}
779
780static inline void
781_thr_check_init(void)
782{
783 if (_thr_initial == NULL)
784 _libpthread_init(NULL);
785}
786
787struct dl_phdr_info;
788void __pthread_cxa_finalize(struct dl_phdr_info *phdr_info);
789void _thr_tsd_unload(struct dl_phdr_info *phdr_info) __hidden;
790void _thr_sigact_unload(struct dl_phdr_info *phdr_info) __hidden;
791
792__END_DECLS
793
794#endif /* !_THR_PRIVATE_H */
640
641/* Default condition variable attributes: */
642extern struct pthread_cond_attr _pthread_condattr_default __hidden;
643
644extern struct pthread_prio _thr_priorities[] __hidden;
645
646extern pid_t _thr_pid __hidden;
647extern int _thr_is_smp __hidden;
648
649extern size_t _thr_guard_default __hidden;
650extern size_t _thr_stack_default __hidden;
651extern size_t _thr_stack_initial __hidden;
652extern int _thr_page_size __hidden;
653extern int _thr_spinloops __hidden;
654extern int _thr_yieldloops __hidden;
655
656/* Garbage thread count. */
657extern int _gc_count __hidden;
658
659extern struct umutex _mutex_static_lock __hidden;
660extern struct umutex _cond_static_lock __hidden;
661extern struct umutex _rwlock_static_lock __hidden;
662extern struct umutex _keytable_lock __hidden;
663extern struct urwlock _thr_list_lock __hidden;
664extern struct umutex _thr_event_lock __hidden;
665
666/*
667 * Function prototype definitions.
668 */
669__BEGIN_DECLS
670int _thr_setthreaded(int) __hidden;
671int _mutex_cv_lock(pthread_mutex_t *, int count) __hidden;
672int _mutex_cv_unlock(pthread_mutex_t *, int *count) __hidden;
673int _mutex_reinit(pthread_mutex_t *) __hidden;
674void _mutex_fork(struct pthread *curthread) __hidden;
675void _libpthread_init(struct pthread *) __hidden;
676struct pthread *_thr_alloc(struct pthread *) __hidden;
677void _thread_exit(const char *, int, const char *) __hidden __dead2;
678int _thr_ref_add(struct pthread *, struct pthread *, int) __hidden;
679void _thr_ref_delete(struct pthread *, struct pthread *) __hidden;
680void _thr_ref_delete_unlocked(struct pthread *, struct pthread *) __hidden;
681int _thr_find_thread(struct pthread *, struct pthread *, int) __hidden;
682void _thr_rtld_init(void) __hidden;
683void _thr_rtld_fini(void) __hidden;
684void _thr_rtld_postfork_child(void) __hidden;
685int _thr_stack_alloc(struct pthread_attr *) __hidden;
686void _thr_stack_free(struct pthread_attr *) __hidden;
687void _thr_free(struct pthread *, struct pthread *) __hidden;
688void _thr_gc(struct pthread *) __hidden;
689void _thread_cleanupspecific(void) __hidden;
690void _thread_printf(int, const char *, ...) __hidden;
691void _thr_spinlock_init(void) __hidden;
692void _thr_cancel_enter(struct pthread *) __hidden;
693void _thr_cancel_enter2(struct pthread *, int) __hidden;
694void _thr_cancel_leave(struct pthread *, int) __hidden;
695void _thr_testcancel(struct pthread *) __hidden;
696void _thr_signal_block(struct pthread *) __hidden;
697void _thr_signal_unblock(struct pthread *) __hidden;
698void _thr_signal_init(void) __hidden;
699void _thr_signal_deinit(void) __hidden;
700int _thr_send_sig(struct pthread *, int sig) __hidden;
701void _thr_list_init(void) __hidden;
702void _thr_hash_add(struct pthread *) __hidden;
703void _thr_hash_remove(struct pthread *) __hidden;
704struct pthread *_thr_hash_find(struct pthread *) __hidden;
705void _thr_link(struct pthread *, struct pthread *) __hidden;
706void _thr_unlink(struct pthread *, struct pthread *) __hidden;
707void _thr_assert_lock_level(void) __hidden __dead2;
708void _thr_ast(struct pthread *) __hidden;
709void _thr_once_init(void) __hidden;
710void _thr_report_creation(struct pthread *curthread,
711 struct pthread *newthread) __hidden;
712void _thr_report_death(struct pthread *curthread) __hidden;
713int _thr_getscheduler(lwpid_t, int *, struct sched_param *) __hidden;
714int _thr_setscheduler(lwpid_t, int, const struct sched_param *) __hidden;
715void _thr_signal_prefork(void) __hidden;
716void _thr_signal_postfork(void) __hidden;
717void _thr_signal_postfork_child(void) __hidden;
718void _thr_try_gc(struct pthread *, struct pthread *) __hidden;
719int _rtp_to_schedparam(const struct rtprio *rtp, int *policy,
720 struct sched_param *param) __hidden;
721int _schedparam_to_rtp(int policy, const struct sched_param *param,
722 struct rtprio *rtp) __hidden;
723void _thread_bp_create(void);
724void _thread_bp_death(void);
725int _sched_yield(void);
726
727void _pthread_cleanup_push(void (*)(void *), void *);
728void _pthread_cleanup_pop(int);
729void _pthread_exit_mask(void *status, sigset_t *mask) __dead2 __hidden;
730void _pthread_cancel_enter(int maycancel);
731void _pthread_cancel_leave(int maycancel);
732
733/* #include <fcntl.h> */
734#ifdef _SYS_FCNTL_H_
735int __sys_fcntl(int, int, ...);
736int __sys_open(const char *, int, ...);
737int __sys_openat(int, const char *, int, ...);
738#endif
739
740/* #include <signal.h> */
741#ifdef _SIGNAL_H_
742int __sys_kill(pid_t, int);
743int __sys_sigaction(int, const struct sigaction *, struct sigaction *);
744int __sys_sigpending(sigset_t *);
745int __sys_sigprocmask(int, const sigset_t *, sigset_t *);
746int __sys_sigsuspend(const sigset_t *);
747int __sys_sigreturn(const ucontext_t *);
748int __sys_sigaltstack(const struct sigaltstack *, struct sigaltstack *);
749int __sys_sigwait(const sigset_t *, int *);
750int __sys_sigtimedwait(const sigset_t *, siginfo_t *,
751 const struct timespec *);
752int __sys_sigwaitinfo(const sigset_t *set, siginfo_t *info);
753#endif
754
755/* #include <time.h> */
756#ifdef _TIME_H_
757int __sys_nanosleep(const struct timespec *, struct timespec *);
758#endif
759
760/* #include <sys/ucontext.h> */
761#ifdef _SYS_UCONTEXT_H_
762int __sys_setcontext(const ucontext_t *ucp);
763int __sys_swapcontext(ucontext_t *oucp, const ucontext_t *ucp);
764#endif
765
766/* #include <unistd.h> */
767#ifdef _UNISTD_H_
768int __sys_close(int);
769int __sys_fork(void);
770pid_t __sys_getpid(void);
771ssize_t __sys_read(int, void *, size_t);
772ssize_t __sys_write(int, const void *, size_t);
773void __sys_exit(int);
774#endif
775
776int _umtx_op_err(void *, int op, u_long, void *, void *) __hidden;
777
778static inline int
779_thr_isthreaded(void)
780{
781 return (__isthreaded != 0);
782}
783
784static inline int
785_thr_is_inited(void)
786{
787 return (_thr_initial != NULL);
788}
789
790static inline void
791_thr_check_init(void)
792{
793 if (_thr_initial == NULL)
794 _libpthread_init(NULL);
795}
796
797struct dl_phdr_info;
798void __pthread_cxa_finalize(struct dl_phdr_info *phdr_info);
799void _thr_tsd_unload(struct dl_phdr_info *phdr_info) __hidden;
800void _thr_sigact_unload(struct dl_phdr_info *phdr_info) __hidden;
801
802__END_DECLS
803
804#endif /* !_THR_PRIVATE_H */