Signed-off-by: Ola Liljedahl <ola.liljed...@linaro.org>
---
Updated to use GCC __atomic facilities (temporary fix). 

 platform/linux-generic/odp_rwlock.c | 24 ++++++++++++++++--------
 1 file changed, 16 insertions(+), 8 deletions(-)

diff --git a/platform/linux-generic/odp_rwlock.c 
b/platform/linux-generic/odp_rwlock.c
index 11c8dd7..2f6a255 100644
--- a/platform/linux-generic/odp_rwlock.c
+++ b/platform/linux-generic/odp_rwlock.c
@@ -4,6 +4,7 @@
  * SPDX-License-Identifier:     BSD-3-Clause
  */
 
+#include <stdbool.h>
 #include <odp_atomic.h>
 #include <odp_rwlock.h>
 
@@ -26,15 +27,18 @@ void odp_rwlock_read_lock(odp_rwlock_t *rwlock)
                        odp_spin();
                        continue;
                }
-               is_locked = odp_atomic_cmpset_u32(
-                                       (volatile uint32_t *)&rwlock->cnt,
-                                             cnt, cnt + 1);
+               is_locked = __atomic_compare_exchange_n(&rwlock->cnt,
+                               &cnt,
+                               cnt + 1,
+                               false/*strong*/,
+                               __ATOMIC_ACQUIRE,
+                               __ATOMIC_RELAXED);
        }
 }
 
 void odp_rwlock_read_unlock(odp_rwlock_t *rwlock)
 {
-       odp_atomic_dec_u32((odp_atomic_u32_t *)(intptr_t)&rwlock->cnt);
+       (void)__atomic_sub_fetch(&rwlock->cnt, 1, __ATOMIC_RELEASE);
 }
 
 void odp_rwlock_write_lock(odp_rwlock_t *rwlock)
@@ -43,19 +47,23 @@ void odp_rwlock_write_lock(odp_rwlock_t *rwlock)
        int is_locked = 0;
 
        while (is_locked == 0) {
+               int32_t zero = 0;
                cnt = rwlock->cnt;
                /* lock aquired, wait */
                if (cnt != 0) {
                        odp_spin();
                        continue;
                }
-               is_locked = odp_atomic_cmpset_u32(
-                                       (volatile uint32_t *)&rwlock->cnt,
-                                             0, -1);
+               is_locked = __atomic_compare_exchange_n(&rwlock->cnt,
+                               &zero,
+                               -1,
+                               false/*strong*/,
+                               __ATOMIC_ACQUIRE,
+                               __ATOMIC_RELAXED);
        }
 }
 
 void odp_rwlock_write_unlock(odp_rwlock_t *rwlock)
 {
-       odp_atomic_inc_u32((odp_atomic_u32_t *)(intptr_t)&rwlock->cnt);
+       (void)__atomic_add_fetch(&rwlock->cnt, 1, __ATOMIC_RELEASE);
 }
-- 
1.9.1


_______________________________________________
lng-odp mailing list
lng-odp@lists.linaro.org
http://lists.linaro.org/mailman/listinfo/lng-odp

Reply via email to