summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGunnar Beutner <gbeutner@serenityos.org>2021-06-02 08:50:08 +0200
committerAndreas Kling <kling@serenityos.org>2021-06-02 18:09:32 +0200
commit5ca1d4289b035918ed989ce4159c39996cddd725 (patch)
treea436648cbf011381bdd3e1089f871a3de5d55b18
parent11fa3e4f92325e265834c05fd1385873f2733ff8 (diff)
downloadserenity-5ca1d4289b035918ed989ce4159c39996cddd725.zip
LibC: Remove reinterpret_cast in pthread_mutex_{try,}lock
-rw-r--r--Userland/Libraries/LibC/pthread_integration.cpp10
1 files changed, 4 insertions, 6 deletions
diff --git a/Userland/Libraries/LibC/pthread_integration.cpp b/Userland/Libraries/LibC/pthread_integration.cpp
index 6a0c895dbc..9b7d3db35f 100644
--- a/Userland/Libraries/LibC/pthread_integration.cpp
+++ b/Userland/Libraries/LibC/pthread_integration.cpp
@@ -93,11 +93,10 @@ int pthread_self() __attribute__((weak, alias("__pthread_self")));
int __pthread_mutex_lock(pthread_mutex_t* mutex)
{
- auto& atomic = reinterpret_cast<Atomic<u32>&>(mutex->lock);
pthread_t this_thread = __pthread_self();
for (;;) {
- u32 expected = false;
- if (!atomic.compare_exchange_strong(expected, true, AK::memory_order_acq_rel)) {
+ u32 expected = 0;
+ if (!AK::atomic_compare_exchange_strong(&mutex->lock, expected, 1u, AK::memory_order_acq_rel)) {
if (mutex->type == __PTHREAD_MUTEX_RECURSIVE && mutex->owner == this_thread) {
mutex->level++;
return 0;
@@ -128,9 +127,8 @@ int pthread_mutex_unlock(pthread_mutex_t*) __attribute__((weak, alias("__pthread
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)) {
+ u32 expected = 0;
+ if (!AK::atomic_compare_exchange_strong(&mutex->lock, expected, 1u, AK::memory_order_acq_rel)) {
if (mutex->type == __PTHREAD_MUTEX_RECURSIVE && mutex->owner == pthread_self()) {
mutex->level++;
return 0;