1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889 |
- #include <endian.h>
- #include <errno.h>
- #include <sysdep.h>
- #include <lowlevellock.h>
- #include <pthread.h>
- #include <pthreadP.h>
- #include <bits/kernel-features.h>
- int
- attribute_protected
- __pthread_cond_broadcast (
- pthread_cond_t *cond)
- {
- int pshared = (cond->__data.__mutex == (void *) ~0l)
- ? LLL_SHARED : LLL_PRIVATE;
-
- lll_lock (cond->__data.__lock, pshared);
-
- if (cond->__data.__total_seq > cond->__data.__wakeup_seq)
- {
-
- cond->__data.__wakeup_seq = cond->__data.__total_seq;
- cond->__data.__woken_seq = cond->__data.__total_seq;
- cond->__data.__futex = (unsigned int) cond->__data.__total_seq * 2;
- int futex_val = cond->__data.__futex;
-
- ++cond->__data.__broadcast_seq;
-
- lll_unlock (cond->__data.__lock, pshared);
-
- if (cond->__data.__mutex == (void *) ~0l)
- goto wake_all;
-
- pthread_mutex_t *mut = (pthread_mutex_t *) cond->__data.__mutex;
-
-
- if (__builtin_expect (mut->__data.__kind
- & (PTHREAD_MUTEX_PRIO_INHERIT_NP
- | PTHREAD_MUTEX_PSHARED_BIT), 0))
- goto wake_all;
-
- if (__builtin_expect (lll_futex_requeue (&cond->__data.__futex, 1,
- INT_MAX, &mut->__data.__lock,
- futex_val, LLL_PRIVATE), 0))
- {
-
- wake_all:
- lll_futex_wake (&cond->__data.__futex, INT_MAX, pshared);
- }
-
- return 0;
- }
-
- lll_unlock (cond->__data.__lock, pshared);
- return 0;
- }
- weak_alias(__pthread_cond_broadcast, pthread_cond_broadcast)
|