1
0
Fork 0
mirror of https://github.com/LadybirdBrowser/ladybird.git synced 2025-06-09 17:44:56 +09:00

LibPthread: Set errno in sem_trywait()

This commit is contained in:
Timur Sultanov 2022-02-16 21:23:24 +03:00 committed by Linus Groh
parent 0a63461341
commit 15cce56411
Notes: sideshowbarker 2024-07-17 10:18:41 +09:00

View file

@ -93,15 +93,19 @@ int sem_trywait(sem_t* sem)
{
u32 value = AK::atomic_load(&sem->value, AK::memory_order_relaxed);
u32 count = value & ~POST_WAKES;
if (count == 0)
return EAGAIN;
if (count == 0) {
errno = EAGAIN;
return -1;
}
// Decrement the count without touching the flag.
u32 desired = (count - 1) | (value & POST_WAKES);
bool exchanged = AK::atomic_compare_exchange_strong(&sem->value, value, desired, AK::memory_order_acquire);
if (exchanged) [[likely]]
if (exchanged) [[likely]] {
return 0;
else
return EAGAIN;
} else {
errno = EAGAIN;
return -1;
}
}
// https://pubs.opengroup.org/onlinepubs/9699919799/functions/sem_wait.html