Signed-off-by: Ola Liljedahl <ola.liljed...@linaro.org> --- Use definitions from odp_atomic_internal.h.
platform/linux-generic/include/api/odp_rwlock.h | 4 ++- platform/linux-generic/odp_rwlock.c | 35 ++++++++++++------------- 2 files changed, 20 insertions(+), 19 deletions(-) diff --git a/platform/linux-generic/include/api/odp_rwlock.h b/platform/linux-generic/include/api/odp_rwlock.h index a880f92..59cf9cc 100644 --- a/platform/linux-generic/include/api/odp_rwlock.h +++ b/platform/linux-generic/include/api/odp_rwlock.h @@ -13,6 +13,8 @@ * ODP RW Locks */ +#include <odp_atomic.h> + #ifdef __cplusplus extern "C" { #endif @@ -28,7 +30,7 @@ extern "C" { * read lock count > 0 */ typedef struct { - volatile int32_t cnt; /**< -1 Write lock, + odp_atomic_u32_t cnt; /**< -1 Write lock, > 0 for Read lock. */ } odp_rwlock_t; diff --git a/platform/linux-generic/odp_rwlock.c b/platform/linux-generic/odp_rwlock.c index 2f6a255..fc78b20 100644 --- a/platform/linux-generic/odp_rwlock.c +++ b/platform/linux-generic/odp_rwlock.c @@ -6,64 +6,63 @@ #include <stdbool.h> #include <odp_atomic.h> +#include <odp_atomic_internal.h> #include <odp_rwlock.h> #include <odp_spin_internal.h> void odp_rwlock_init(odp_rwlock_t *rwlock) { - rwlock->cnt = 0; + odp_atomic_init_u32(&rwlock->cnt, 0); } void odp_rwlock_read_lock(odp_rwlock_t *rwlock) { - int32_t cnt; + uint32_t cnt; int is_locked = 0; while (is_locked == 0) { - cnt = rwlock->cnt; + cnt = odp_atomic_u32_load_mm(&rwlock->cnt, ODP_MEMMODEL_RLX); /* waiting for read lock */ - if (cnt < 0) { + if ((int32_t)cnt < 0) { odp_spin(); continue; } - is_locked = __atomic_compare_exchange_n(&rwlock->cnt, + is_locked = odp_atomic_u32_cmp_xchg_strong_mm(&rwlock->cnt, &cnt, cnt + 1, - false/*strong*/, - __ATOMIC_ACQUIRE, - __ATOMIC_RELAXED); + ODP_MEMMODEL_ACQ, + ODP_MEMMODEL_RLX); } } void odp_rwlock_read_unlock(odp_rwlock_t *rwlock) { - (void)__atomic_sub_fetch(&rwlock->cnt, 1, __ATOMIC_RELEASE); + odp_atomic_u32_sub_mm(&rwlock->cnt, 1, ODP_MEMMODEL_RLS); } void odp_rwlock_write_lock(odp_rwlock_t *rwlock) { - int32_t cnt; + uint32_t cnt; int is_locked = 0; while (is_locked == 0) { - int32_t zero = 0; - cnt = rwlock->cnt; + uint32_t zero = 0; + cnt = odp_atomic_u32_load_mm(&rwlock->cnt, ODP_MEMMODEL_RLX); /* lock aquired, wait */ if (cnt != 0) { odp_spin(); continue; } - is_locked = __atomic_compare_exchange_n(&rwlock->cnt, + is_locked = odp_atomic_u32_cmp_xchg_strong_mm(&rwlock->cnt, &zero, - -1, - false/*strong*/, - __ATOMIC_ACQUIRE, - __ATOMIC_RELAXED); + (uint32_t)-1, + ODP_MEMMODEL_ACQ, + ODP_MEMMODEL_RLX); } } void odp_rwlock_write_unlock(odp_rwlock_t *rwlock) { - (void)__atomic_add_fetch(&rwlock->cnt, 1, __ATOMIC_RELEASE); + odp_atomic_u32_store_mm(&rwlock->cnt, 0, ODP_MEMMODEL_RLS); } -- 1.9.1 _______________________________________________ lng-odp mailing list lng-odp@lists.linaro.org http://lists.linaro.org/mailman/listinfo/lng-odp