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:
parent
0a63461341
commit
15cce56411
Notes:
sideshowbarker
2024-07-17 10:18:41 +09:00
Author: https://github.com/TSultanov
Commit: 15cce56411
Pull-request: https://github.com/SerenityOS/serenity/pull/14260
Reviewed-by: https://github.com/ADKaster
Reviewed-by: https://github.com/linusg
1 changed files with 9 additions and 5 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue