mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 08:58:11 +00:00
LibC: Move the __pthread_mutex_trylock function to LibC
Let's move this to LibC because the dynamic loader depends on this function.
This commit is contained in:
parent
acd65a5f86
commit
549d9bd3ea
3 changed files with 20 additions and 12 deletions
|
@ -19,6 +19,7 @@ void __pthread_fork_atfork_register_parent(void (*)(void));
|
||||||
void __pthread_fork_atfork_register_child(void (*)(void));
|
void __pthread_fork_atfork_register_child(void (*)(void));
|
||||||
|
|
||||||
int __pthread_mutex_lock(pthread_mutex_t*);
|
int __pthread_mutex_lock(pthread_mutex_t*);
|
||||||
|
int __pthread_mutex_trylock(pthread_mutex_t*);
|
||||||
int __pthread_mutex_unlock(pthread_mutex_t*);
|
int __pthread_mutex_unlock(pthread_mutex_t*);
|
||||||
int __pthread_mutex_init(pthread_mutex_t*, const pthread_mutexattr_t*);
|
int __pthread_mutex_init(pthread_mutex_t*, const pthread_mutexattr_t*);
|
||||||
|
|
||||||
|
|
|
@ -125,6 +125,24 @@ int __pthread_mutex_unlock(pthread_mutex_t* mutex)
|
||||||
|
|
||||||
int pthread_mutex_unlock(pthread_mutex_t*) __attribute__((weak, alias("__pthread_mutex_unlock")));
|
int pthread_mutex_unlock(pthread_mutex_t*) __attribute__((weak, alias("__pthread_mutex_unlock")));
|
||||||
|
|
||||||
|
int __pthread_mutex_trylock(pthread_mutex_t* mutex)
|
||||||
|
{
|
||||||
|
auto& atomic = reinterpret_cast<Atomic<u32>&>(mutex->lock);
|
||||||
|
u32 expected = false;
|
||||||
|
if (!atomic.compare_exchange_strong(expected, true, AK::memory_order_acq_rel)) {
|
||||||
|
if (mutex->type == __PTHREAD_MUTEX_RECURSIVE && mutex->owner == pthread_self()) {
|
||||||
|
mutex->level++;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
return EBUSY;
|
||||||
|
}
|
||||||
|
mutex->owner = pthread_self();
|
||||||
|
mutex->level = 0;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int pthread_mutex_trylock(pthread_mutex_t* mutex) __attribute__((weak, alias("__pthread_mutex_trylock")));
|
||||||
|
|
||||||
int __pthread_mutex_init(pthread_mutex_t* mutex, const pthread_mutexattr_t* attributes)
|
int __pthread_mutex_init(pthread_mutex_t* mutex, const pthread_mutexattr_t* attributes)
|
||||||
{
|
{
|
||||||
mutex->lock = 0;
|
mutex->lock = 0;
|
||||||
|
|
|
@ -167,18 +167,7 @@ int pthread_mutex_lock(pthread_mutex_t* mutex)
|
||||||
|
|
||||||
int pthread_mutex_trylock(pthread_mutex_t* mutex)
|
int pthread_mutex_trylock(pthread_mutex_t* mutex)
|
||||||
{
|
{
|
||||||
auto& atomic = reinterpret_cast<Atomic<u32>&>(mutex->lock);
|
return __pthread_mutex_trylock(mutex);
|
||||||
u32 expected = false;
|
|
||||||
if (!atomic.compare_exchange_strong(expected, true, AK::memory_order_acq_rel)) {
|
|
||||||
if (mutex->type == PTHREAD_MUTEX_RECURSIVE && mutex->owner == pthread_self()) {
|
|
||||||
mutex->level++;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
return EBUSY;
|
|
||||||
}
|
|
||||||
mutex->owner = pthread_self();
|
|
||||||
mutex->level = 0;
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int pthread_mutex_unlock(pthread_mutex_t* mutex)
|
int pthread_mutex_unlock(pthread_mutex_t* mutex)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue