LibPthread: Fix ordering
It would be enough to use relaxed ordering here if it weren't for the mutex, which we also need to store and retrieve. To ensure the pthread_cond_broadcast() call sees the store, use release and acquire as appropriate. Thankfully, both of these are on the slow paths.
This commit is contained in:
parent
30caa33f7e
commit
78f5c4a4c2
Notes:
sideshowbarker
2024-07-18 10:17:29 +09:00
Author: https://github.com/bugaevc Commit: https://github.com/SerenityOS/serenity/commit/78f5c4a4c29 Pull-request: https://github.com/SerenityOS/serenity/pull/8495
1 changed files with 2 additions and 2 deletions
|
@ -73,7 +73,7 @@ int pthread_cond_timedwait(pthread_cond_t* cond, pthread_mutex_t* mutex, const s
|
|||
// Fetch the current value, and record that we're about to wait. Fetching
|
||||
// the current value has to be done while we hold the mutex, because the
|
||||
// value might change as soon as we unlock it.
|
||||
u32 value = AK::atomic_fetch_or(&cond->value, NEED_TO_WAKE_ONE | NEED_TO_WAKE_ALL, AK::memory_order_relaxed) | NEED_TO_WAKE_ONE | NEED_TO_WAKE_ALL;
|
||||
u32 value = AK::atomic_fetch_or(&cond->value, NEED_TO_WAKE_ONE | NEED_TO_WAKE_ALL, AK::memory_order_release) | NEED_TO_WAKE_ONE | NEED_TO_WAKE_ALL;
|
||||
pthread_mutex_unlock(mutex);
|
||||
int rc = futex_wait(&cond->value, value, abstime, cond->clockid);
|
||||
if (rc < 0 && errno != EAGAIN)
|
||||
|
@ -122,7 +122,7 @@ int pthread_cond_broadcast(pthread_cond_t* cond)
|
|||
if (!(value & NEED_TO_WAKE_ALL)) [[likely]]
|
||||
return 0;
|
||||
|
||||
AK::atomic_fetch_and(&cond->value, ~(NEED_TO_WAKE_ONE | NEED_TO_WAKE_ALL), AK::memory_order_relaxed);
|
||||
AK::atomic_fetch_and(&cond->value, ~(NEED_TO_WAKE_ONE | NEED_TO_WAKE_ALL), AK::memory_order_acquire);
|
||||
|
||||
pthread_mutex_t* mutex = AK::atomic_load(&cond->mutex, AK::memory_order_relaxed);
|
||||
VERIFY(mutex);
|
||||
|
|
Loading…
Add table
Reference in a new issue