1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 05:48:12 +00:00

LibPthread: Implement pthread_mutex_trylock()

This commit is contained in:
Andreas Kling 2019-12-07 14:32:48 +01:00
parent 594c7f2d83
commit babb726212

View file

@ -111,6 +111,15 @@ int pthread_mutex_lock(pthread_mutex_t* mutex)
}
}
int pthread_mutex_trylock(pthread_mutex_t* mutex)
{
auto* atomic = reinterpret_cast<Atomic<u32>*>(mutex);
u32 expected = false;
if (atomic->compare_exchange_strong(expected, true, AK::memory_order_acq_rel))
return 0;
return EBUSY;
}
int pthread_mutex_unlock(pthread_mutex_t* mutex)
{
auto* atomic = reinterpret_cast<Atomic<u32>*>(mutex);