diff mbox

[v3,2/9] linux-generic: odp_rwlock.c use __atomic

Message ID 1416868730-26140-3-git-send-email-ola.liljedahl@linaro.org
State Accepted
Commit 7c71d2979476c2762a446c0a71731637efd6d0b8
Headers show

Commit Message

Ola Liljedahl Nov. 24, 2014, 10:38 p.m. UTC
Signed-off-by: Ola Liljedahl <ola.liljedahl@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 mbox

Patch

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);
 }