1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20: #include <endian.h>
21: #include <errno.h>
22: #include <sysdep.h>
23: #include <lowlevellock.h>
24: #include <pthread.h>
25: #include <pthreadP.h>
26:
27: #include <shlib-compat.h>
28: #include <kernel-features.h>
29:
30:
31: int
32: __pthread_cond_broadcast (cond)
33: pthread_cond_t *cond;
34: {
35: int pshared = (cond->__data.__mutex == (void *) ~0l)
36: ? LLL_SHARED : LLL_PRIVATE;
37:
38: lll_lock (cond->__data.__lock, pshared);
39:
40:
41: if (cond->__data.__total_seq > cond->__data.__wakeup_seq)
42: {
43:
44: cond->__data.__wakeup_seq = cond->__data.__total_seq;
45: cond->__data.__woken_seq = cond->__data.__total_seq;
46: cond->__data.__futex = (unsigned int) cond->__data.__total_seq * 2;
47: int futex_val = cond->__data.__futex;
48:
49: ++cond->__data.__broadcast_seq;
50:
51:
52: lll_unlock (cond->__data.__lock, pshared);
53:
54:
55: if (cond->__data.__mutex == (void *) ~0l)
56: goto wake_all;
57:
58:
59: pthread_mutex_t *mut = (pthread_mutex_t *) cond->__data.__mutex;
60:
61:
62:
63:
64: if (__builtin_expect (mut->__data.__kind
65: & (PTHREAD_MUTEX_PRIO_INHERIT_NP
66: | PTHREAD_MUTEX_PSHARED_BIT), 0))
67: goto wake_all;
68:
69:
70:
71: if (__builtin_expect (lll_futex_requeue (&cond->__data.__futex, 1,
72: INT_MAX, &mut->__data.__lock,
73: futex_val, LLL_PRIVATE), 0))
74: {
75:
76: wake_all:
77: lll_futex_wake (&cond->__data.__futex, INT_MAX, pshared);
78: }
79:
80:
81: return 0;
82: }
83:
84:
85: lll_unlock (cond->__data.__lock, pshared);
86:
87: return 0;
88: }
89:
90: versioned_symbol (libpthread, __pthread_cond_broadcast, pthread_cond_broadcast,
91: GLIBC_2_3_2);