thr_private.h (214334) | thr_private.h (216641) |
---|---|
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 --- 12 unchanged lines hidden (view full) --- 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 --- 12 unchanged lines hidden (view full) --- 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 214334 2010-10-25 09:16:04Z davidxu $ | 29 * $FreeBSD: head/lib/libthr/thread/thr_private.h 216641 2010-12-22 05:01:52Z davidxu $ |
30 */ 31 32#ifndef _THR_PRIVATE_H 33#define _THR_PRIVATE_H 34 35/* 36 * Include files. 37 */ --- 92 unchanged lines hidden (view full) --- 130#define THR_MUTEX_INITIALIZER ((struct pthread_mutex *)NULL) 131#define THR_ADAPTIVE_MUTEX_INITIALIZER ((struct pthread_mutex *)1) 132#define THR_MUTEX_DESTROYED ((struct pthread_mutex *)2) 133#define THR_COND_INITIALIZER ((struct pthread_cond *)NULL) 134#define THR_COND_DESTROYED ((struct pthread_cond *)1) 135#define THR_RWLOCK_INITIALIZER ((struct pthread_rwlock *)NULL) 136#define THR_RWLOCK_DESTROYED ((struct pthread_rwlock *)1) 137 | 30 */ 31 32#ifndef _THR_PRIVATE_H 33#define _THR_PRIVATE_H 34 35/* 36 * Include files. 37 */ --- 92 unchanged lines hidden (view full) --- 130#define THR_MUTEX_INITIALIZER ((struct pthread_mutex *)NULL) 131#define THR_ADAPTIVE_MUTEX_INITIALIZER ((struct pthread_mutex *)1) 132#define THR_MUTEX_DESTROYED ((struct pthread_mutex *)2) 133#define THR_COND_INITIALIZER ((struct pthread_cond *)NULL) 134#define THR_COND_DESTROYED ((struct pthread_cond *)1) 135#define THR_RWLOCK_INITIALIZER ((struct pthread_rwlock *)NULL) 136#define THR_RWLOCK_DESTROYED ((struct pthread_rwlock *)1) 137 |
138#define PMUTEX_FLAG_TYPE_MASK 0x0ff 139#define PMUTEX_FLAG_PRIVATE 0x100 140#define PMUTEX_FLAG_DEFERED 0x200 141#define PMUTEX_TYPE(mtxflags) ((mtxflags) & PMUTEX_FLAG_TYPE_MASK) 142 143#define MAX_DEFER_WAITERS 50 144 |
|
138struct pthread_mutex { 139 /* 140 * Lock for accesses to this structure. 141 */ 142 struct umutex m_lock; | 145struct pthread_mutex { 146 /* 147 * Lock for accesses to this structure. 148 */ 149 struct umutex m_lock; |
143 enum pthread_mutextype m_type; | 150 int m_flags; |
144 struct pthread *m_owner; 145 int m_count; | 151 struct pthread *m_owner; 152 int m_count; |
146 int m_refcount; | |
147 int m_spinloops; 148 int m_yieldloops; | 153 int m_spinloops; 154 int m_yieldloops; |
149 int m_private; | |
150 /* 151 * Link for all mutexes a thread currently owns. 152 */ 153 TAILQ_ENTRY(pthread_mutex) m_qe; 154}; 155 156struct pthread_mutex_attr { 157 enum pthread_mutextype m_type; 158 int m_protocol; 159 int m_ceiling; 160}; 161 162#define PTHREAD_MUTEXATTR_STATIC_INITIALIZER \ 163 { PTHREAD_MUTEX_DEFAULT, PTHREAD_PRIO_NONE, 0, MUTEX_FLAGS_PRIVATE } 164 165struct pthread_cond { | 155 /* 156 * Link for all mutexes a thread currently owns. 157 */ 158 TAILQ_ENTRY(pthread_mutex) m_qe; 159}; 160 161struct pthread_mutex_attr { 162 enum pthread_mutextype m_type; 163 int m_protocol; 164 int m_ceiling; 165}; 166 167#define PTHREAD_MUTEXATTR_STATIC_INITIALIZER \ 168 { PTHREAD_MUTEX_DEFAULT, PTHREAD_PRIO_NONE, 0, MUTEX_FLAGS_PRIVATE } 169 170struct pthread_cond { |
166 struct umutex c_lock; 167 struct ucond c_kerncv; 168 int c_pshared; 169 int c_clockid; | 171 __uint32_t __has_user_waiters; 172 __uint32_t __has_kern_waiters; 173 __uint32_t __flags; 174 __uint32_t __clock_id; |
170}; 171 172struct pthread_cond_attr { 173 int c_pshared; 174 int c_clockid; 175}; 176 177struct pthread_barrier { --- 62 unchanged lines hidden (view full) --- 240 void *stackaddr_attr; 241 size_t stacksize_attr; 242 size_t guardsize_attr; 243#define pthread_attr_end_copy cpuset 244 cpuset_t *cpuset; 245 size_t cpusetsize; 246}; 247 | 175}; 176 177struct pthread_cond_attr { 178 int c_pshared; 179 int c_clockid; 180}; 181 182struct pthread_barrier { --- 62 unchanged lines hidden (view full) --- 245 void *stackaddr_attr; 246 size_t stacksize_attr; 247 size_t guardsize_attr; 248#define pthread_attr_end_copy cpuset 249 cpuset_t *cpuset; 250 size_t cpusetsize; 251}; 252 |
253struct wake_addr { 254 struct wake_addr *link; 255 unsigned int value; 256 char pad[12]; 257}; 258 259struct sleepqueue { 260 TAILQ_HEAD(, pthread) sq_blocked; 261 SLIST_HEAD(, sleepqueue) sq_freeq; 262 LIST_ENTRY(sleepqueue) sq_hash; 263 SLIST_ENTRY(sleepqueue) sq_flink; 264 void *sq_wchan; 265 int sq_type; 266}; 267 |
|
248/* 249 * Thread creation state attributes. 250 */ 251#define THR_CREATE_RUNNING 0 252#define THR_CREATE_SUSPENDED 1 253 254/* 255 * Miscellaneous definitions. --- 95 unchanged lines hidden (view full) --- 351 TAILQ_ENTRY(pthread) tle; /* link for all threads in process */ 352 353 /* Queue entry for GC lists. */ 354 TAILQ_ENTRY(pthread) gcle; 355 356 /* Hash queue entry. */ 357 LIST_ENTRY(pthread) hle; 358 | 268/* 269 * Thread creation state attributes. 270 */ 271#define THR_CREATE_RUNNING 0 272#define THR_CREATE_SUSPENDED 1 273 274/* 275 * Miscellaneous definitions. --- 95 unchanged lines hidden (view full) --- 371 TAILQ_ENTRY(pthread) tle; /* link for all threads in process */ 372 373 /* Queue entry for GC lists. */ 374 TAILQ_ENTRY(pthread) gcle; 375 376 /* Hash queue entry. */ 377 LIST_ENTRY(pthread) hle; 378 |
379 /* Sleep queue entry */ 380 TAILQ_ENTRY(pthread) wle; 381 |
|
359 /* Threads reference count. */ 360 int refcount; 361 362 /* 363 * Thread start routine, argument, stack pointer and thread 364 * attributes. 365 */ 366 void *(*start_routine)(void *); --- 110 unchanged lines hidden (view full) --- 477 /* Enable event reporting */ 478 int report_events; 479 480 /* Event mask */ 481 int event_mask; 482 483 /* Event */ 484 td_event_msg_t event_buf; | 382 /* Threads reference count. */ 383 int refcount; 384 385 /* 386 * Thread start routine, argument, stack pointer and thread 387 * attributes. 388 */ 389 void *(*start_routine)(void *); --- 110 unchanged lines hidden (view full) --- 500 /* Enable event reporting */ 501 int report_events; 502 503 /* Event mask */ 504 int event_mask; 505 506 /* Event */ 507 td_event_msg_t event_buf; |
508 509 struct wake_addr *wake_addr; 510#define WAKE_ADDR(td) ((td)->wake_addr) 511 512 /* Sleep queue */ 513 struct sleepqueue *sleepqueue; 514 515 /* Wait channel */ 516 void *wchan; 517 518 /* Referenced mutex. */ 519 struct pthread_mutex *mutex_obj; 520 521 /* Thread will sleep. */ 522 int will_sleep; 523 524 /* Number of threads deferred. */ 525 int nwaiter_defer; 526 527 /* Deferred threads from pthread_cond_signal. */ 528 unsigned int *defer_waiters[MAX_DEFER_WAITERS]; |
|
485}; 486 487#define THR_SHOULD_GC(thrd) \ 488 ((thrd)->refcount == 0 && (thrd)->state == PS_DEAD && \ 489 ((thrd)->flags & THR_FLAGS_DETACHED) != 0) 490 491#define THR_IN_CRITICAL(thrd) \ 492 (((thrd)->locklevel > 0) || \ --- 21 unchanged lines hidden (view full) --- 514 _thr_umutex_unlock((lck), TID(thrd)) 515 516#define THR_LOCK_ACQUIRE(thrd, lck) \ 517do { \ 518 (thrd)->locklevel++; \ 519 _thr_umutex_lock(lck, TID(thrd)); \ 520} while (0) 521 | 529}; 530 531#define THR_SHOULD_GC(thrd) \ 532 ((thrd)->refcount == 0 && (thrd)->state == PS_DEAD && \ 533 ((thrd)->flags & THR_FLAGS_DETACHED) != 0) 534 535#define THR_IN_CRITICAL(thrd) \ 536 (((thrd)->locklevel > 0) || \ --- 21 unchanged lines hidden (view full) --- 558 _thr_umutex_unlock((lck), TID(thrd)) 559 560#define THR_LOCK_ACQUIRE(thrd, lck) \ 561do { \ 562 (thrd)->locklevel++; \ 563 _thr_umutex_lock(lck, TID(thrd)); \ 564} while (0) 565 |
566#define THR_LOCK_ACQUIRE_SPIN(thrd, lck) \ 567do { \ 568 (thrd)->locklevel++; \ 569 _thr_umutex_lock_spin(lck, TID(thrd)); \ 570} while (0) 571 |
|
522#ifdef _PTHREADS_INVARIANTS 523#define THR_ASSERT_LOCKLEVEL(thrd) \ 524do { \ 525 if (__predict_false((thrd)->locklevel <= 0)) \ 526 _thr_assert_lock_level(); \ 527} while (0) 528#else 529#define THR_ASSERT_LOCKLEVEL(thrd) --- 136 unchanged lines hidden (view full) --- 666extern struct urwlock _thr_list_lock __hidden; 667extern struct umutex _thr_event_lock __hidden; 668 669/* 670 * Function prototype definitions. 671 */ 672__BEGIN_DECLS 673int _thr_setthreaded(int) __hidden; | 572#ifdef _PTHREADS_INVARIANTS 573#define THR_ASSERT_LOCKLEVEL(thrd) \ 574do { \ 575 if (__predict_false((thrd)->locklevel <= 0)) \ 576 _thr_assert_lock_level(); \ 577} while (0) 578#else 579#define THR_ASSERT_LOCKLEVEL(thrd) --- 136 unchanged lines hidden (view full) --- 716extern struct urwlock _thr_list_lock __hidden; 717extern struct umutex _thr_event_lock __hidden; 718 719/* 720 * Function prototype definitions. 721 */ 722__BEGIN_DECLS 723int _thr_setthreaded(int) __hidden; |
674int _mutex_cv_lock(pthread_mutex_t *, int count) __hidden; 675int _mutex_cv_unlock(pthread_mutex_t *, int *count) __hidden; | 724int _mutex_cv_lock(struct pthread_mutex *, int count) __hidden; 725int _mutex_cv_unlock(struct pthread_mutex *, int *count) __hidden; 726int _mutex_cv_attach(struct pthread_mutex *, int count) __hidden; 727int _mutex_cv_detach(struct pthread_mutex *, int *count) __hidden; 728int _mutex_owned(struct pthread *, const struct pthread_mutex *) __hidden; |
676int _mutex_reinit(pthread_mutex_t *) __hidden; 677void _mutex_fork(struct pthread *curthread) __hidden; 678void _libpthread_init(struct pthread *) __hidden; 679struct pthread *_thr_alloc(struct pthread *) __hidden; 680void _thread_exit(const char *, int, const char *) __hidden __dead2; 681int _thr_ref_add(struct pthread *, struct pthread *, int) __hidden; 682void _thr_ref_delete(struct pthread *, struct pthread *) __hidden; 683void _thr_ref_delete_unlocked(struct pthread *, struct pthread *) __hidden; --- 108 unchanged lines hidden (view full) --- 792 793static inline void 794_thr_check_init(void) 795{ 796 if (_thr_initial == NULL) 797 _libpthread_init(NULL); 798} 799 | 729int _mutex_reinit(pthread_mutex_t *) __hidden; 730void _mutex_fork(struct pthread *curthread) __hidden; 731void _libpthread_init(struct pthread *) __hidden; 732struct pthread *_thr_alloc(struct pthread *) __hidden; 733void _thread_exit(const char *, int, const char *) __hidden __dead2; 734int _thr_ref_add(struct pthread *, struct pthread *, int) __hidden; 735void _thr_ref_delete(struct pthread *, struct pthread *) __hidden; 736void _thr_ref_delete_unlocked(struct pthread *, struct pthread *) __hidden; --- 108 unchanged lines hidden (view full) --- 845 846static inline void 847_thr_check_init(void) 848{ 849 if (_thr_initial == NULL) 850 _libpthread_init(NULL); 851} 852 |
853struct wake_addr *_thr_alloc_wake_addr(void); 854void _thr_release_wake_addr(struct wake_addr *); 855int _thr_sleep(struct pthread *, int, const struct timespec *); 856 857void _thr_wake_addr_init(void) __hidden; 858 859static inline void 860_thr_clear_wake(struct pthread *td) 861{ 862 td->wake_addr->value = 0; 863} 864 865static inline int 866_thr_is_woken(struct pthread *td) 867{ 868 return td->wake_addr->value != 0; 869} 870 871static inline void 872_thr_set_wake(unsigned int *waddr) 873{ 874 *waddr = 1; 875 _thr_umtx_wake(waddr, INT_MAX, 0); 876} 877 878void _thr_wake_all(unsigned int *waddrs[], int) __hidden; 879 880static inline struct pthread * 881_sleepq_first(struct sleepqueue *sq) 882{ 883 return TAILQ_FIRST(&sq->sq_blocked); 884} 885 886void _sleepq_init(void) __hidden; 887struct sleepqueue *_sleepq_alloc(void) __hidden; 888void _sleepq_free(struct sleepqueue *) __hidden; 889void _sleepq_lock(void *) __hidden; 890void _sleepq_unlock(void *) __hidden; 891struct sleepqueue *_sleepq_lookup(void *) __hidden; 892void _sleepq_add(void *, struct pthread *) __hidden; 893int _sleepq_remove(struct sleepqueue *, struct pthread *) __hidden; 894void _sleepq_drop(struct sleepqueue *, 895 void (*cb)(struct pthread *, void *arg), void *) __hidden; 896 |
|
800struct dl_phdr_info; 801void __pthread_cxa_finalize(struct dl_phdr_info *phdr_info); 802void _thr_tsd_unload(struct dl_phdr_info *phdr_info) __hidden; 803void _thr_sigact_unload(struct dl_phdr_info *phdr_info) __hidden; 804 805__END_DECLS 806 807#endif /* !_THR_PRIVATE_H */ | 897struct dl_phdr_info; 898void __pthread_cxa_finalize(struct dl_phdr_info *phdr_info); 899void _thr_tsd_unload(struct dl_phdr_info *phdr_info) __hidden; 900void _thr_sigact_unload(struct dl_phdr_info *phdr_info) __hidden; 901 902__END_DECLS 903 904#endif /* !_THR_PRIVATE_H */ |