LibPthread: Implement pthread_mutex_trylock()
This commit is contained in:
parent
594c7f2d83
commit
babb726212
Notes:
sideshowbarker
2024-07-19 10:56:36 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/babb7262122
1 changed files with 9 additions and 0 deletions
|
@ -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);
|
||||
|
|
Loading…
Add table
Reference in a new issue