From 13e73e39ccae75173d215e48d5bdab9f548c70ec Mon Sep 17 00:00:00 2001 From: Jesse Natalie Date: Fri, 8 Jul 2022 11:16:14 -0700 Subject: [PATCH] simple_mtx: Replace GCC sync intrinsics with u_atomic ops MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Reviewed-by: Yonggang Luo Reviewed-by: Marek Olšák Part-of: --- src/util/simple_mtx.h | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/util/simple_mtx.h b/src/util/simple_mtx.h index b44ddf5386a..9434745fbd1 100644 --- a/src/util/simple_mtx.h +++ b/src/util/simple_mtx.h @@ -26,6 +26,7 @@ #include "util/futex.h" #include "util/macros.h" +#include "u_atomic.h" #include "c11/threads.h" @@ -95,16 +96,16 @@ simple_mtx_lock(simple_mtx_t *mtx) { uint32_t c; - c = __sync_val_compare_and_swap(&mtx->val, 0, 1); + c = p_atomic_cmpxchg(&mtx->val, 0, 1); assert(c != _SIMPLE_MTX_INVALID_VALUE); if (__builtin_expect(c != 0, 0)) { if (c != 2) - c = __sync_lock_test_and_set(&mtx->val, 2); + c = p_atomic_xchg(&mtx->val, 2); while (c != 0) { futex_wait(&mtx->val, 2, NULL); - c = __sync_lock_test_and_set(&mtx->val, 2); + c = p_atomic_xchg(&mtx->val, 2); } } @@ -118,7 +119,7 @@ simple_mtx_unlock(simple_mtx_t *mtx) HG(ANNOTATE_RWLOCK_RELEASED(mtx, 1)); - c = __sync_fetch_and_sub(&mtx->val, 1); + c = p_atomic_fetch_add(&mtx->val, -1); assert(c != _SIMPLE_MTX_INVALID_VALUE);