mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 04:27:44 +00:00
LibPthread: Set errno in sem_trywait()
This commit is contained in:
parent
0a63461341
commit
15cce56411
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 value = AK::atomic_load(&sem->value, AK::memory_order_relaxed);
|
||||||
u32 count = value & ~POST_WAKES;
|
u32 count = value & ~POST_WAKES;
|
||||||
if (count == 0)
|
if (count == 0) {
|
||||||
return EAGAIN;
|
errno = EAGAIN;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
// Decrement the count without touching the flag.
|
// Decrement the count without touching the flag.
|
||||||
u32 desired = (count - 1) | (value & POST_WAKES);
|
u32 desired = (count - 1) | (value & POST_WAKES);
|
||||||
bool exchanged = AK::atomic_compare_exchange_strong(&sem->value, value, desired, AK::memory_order_acquire);
|
bool exchanged = AK::atomic_compare_exchange_strong(&sem->value, value, desired, AK::memory_order_acquire);
|
||||||
if (exchanged) [[likely]]
|
if (exchanged) [[likely]] {
|
||||||
return 0;
|
return 0;
|
||||||
else
|
} else {
|
||||||
return EAGAIN;
|
errno = EAGAIN;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://pubs.opengroup.org/onlinepubs/9699919799/functions/sem_wait.html
|
// https://pubs.opengroup.org/onlinepubs/9699919799/functions/sem_wait.html
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue