@@ -34,15 +34,16 @@ bool __time_critical_func(cond_wait_until)(cond_t *cond, mutex_t *mtx, absolute_
34
34
spin_lock_unsafe_blocking (cond -> core .spin_lock );
35
35
}
36
36
37
- // Release the mutex but without restoring interrupts and notify.
38
37
mtx -> owner = LOCK_INVALID_OWNER_ID ;
39
- if (!same_spinlock ) {
40
- spin_unlock_unsafe (mtx -> core .spin_lock );
41
- }
42
38
43
39
uint64_t current_broadcast = cond -> broadcast_count ;
44
40
45
41
if (lock_is_owner_id_valid (cond -> waiter )) {
42
+ // Release the mutex but without restoring interrupts and notify.
43
+ if (!same_spinlock ) {
44
+ spin_unlock_unsafe (mtx -> core .spin_lock );
45
+ }
46
+
46
47
// There is a valid owner of the condition variable: we are not the
47
48
// first waiter.
48
49
// First iteration: notify
@@ -68,8 +69,11 @@ bool __time_critical_func(cond_wait_until)(cond_t *cond, mutex_t *mtx, absolute_
68
69
save = spin_lock_blocking (cond -> core .spin_lock );
69
70
} while (true);
70
71
} else {
71
- // Notify to finish release of mutex
72
- __sev ();
72
+ // Release the mutex but without restoring interrupts
73
+ if (!same_spinlock ) {
74
+ uint32_t disabled_ints = save_and_disable_interrupts ();
75
+ lock_internal_spin_unlock_with_notify (& mtx -> core , disabled_ints );
76
+ }
73
77
}
74
78
75
79
if (success && cond -> broadcast_count == current_broadcast ) {
@@ -97,13 +101,14 @@ bool __time_critical_func(cond_wait_until)(cond_t *cond, mutex_t *mtx, absolute_
97
101
}
98
102
99
103
// We got the signal (or timed out)
100
- // Acquire the mutex spin lock and release the core spin lock.
101
- if (!same_spinlock ) {
102
- spin_lock_unsafe_blocking (mtx -> core .spin_lock );
103
- spin_unlock_unsafe (cond -> core .spin_lock );
104
- }
105
104
106
105
if (lock_is_owner_id_valid (mtx -> owner )) {
106
+ // Acquire the mutex spin lock and release the core spin lock.
107
+ if (!same_spinlock ) {
108
+ spin_lock_unsafe_blocking (mtx -> core .spin_lock );
109
+ spin_unlock_unsafe (cond -> core .spin_lock );
110
+ }
111
+
107
112
// Another core holds the mutex.
108
113
// First iteration: notify
109
114
lock_internal_spin_unlock_with_notify (& mtx -> core , save );
@@ -118,12 +123,19 @@ bool __time_critical_func(cond_wait_until)(cond_t *cond, mutex_t *mtx, absolute_
118
123
save = spin_lock_blocking (mtx -> core .spin_lock );
119
124
} while (true);
120
125
} else {
121
- // Notify to finish release of condition variable
122
- __sev ();
126
+ // Acquire the mutex spin lock and release the core spin lock
127
+ // with notify but without restoring interrupts
128
+ if (!same_spinlock ) {
129
+ spin_lock_unsafe_blocking (mtx -> core .spin_lock );
130
+ uint32_t disabled_ints = save_and_disable_interrupts ();
131
+ lock_internal_spin_unlock_with_notify (& cond -> core , disabled_ints );
132
+ }
123
133
}
124
134
125
135
// Eventually hold the mutex.
126
136
mtx -> owner = caller ;
137
+
138
+ // Restore the interrupts now
127
139
spin_unlock (mtx -> core .spin_lock , save );
128
140
129
141
return success ;
0 commit comments