[Mesa-dev] [PATCH 2/2] util/u_atomic: Add implementation of __sync_val_compare_and_swap_8

Matt Turner mattst88 at gmail.com
Thu Sep 14 19:07:25 UTC 2017


Needed for 32-bit PowerPC.
---
 src/util/u_atomic.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

diff --git a/src/util/u_atomic.c b/src/util/u_atomic.c
index 44b75fb0c0..b32527fe34 100644
--- a/src/util/u_atomic.c
+++ b/src/util/u_atomic.c
@@ -61,6 +61,20 @@ __sync_sub_and_fetch_8(uint64_t *ptr, uint64_t val)
 }
 
 WEAK uint64_t
+__sync_val_compare_and_swap_8(uint64_t *ptr, uint64_t oldval, uint64_t newval)
+{
+   uint64_t r;
+
+   pthread_mutex_lock(&sync_mutex);
+   r = *ptr;
+   if (*ptr == oldval)
+      *ptr = newval;
+   pthread_mutex_unlock(&sync_mutex);
+
+   return r;
+}
+
+WEAK uint64_t
 __atomic_fetch_add_8(uint64_t *ptr, uint64_t val, int memorder)
 {
    return __sync_add_and_fetch(ptr, val);
-- 
2.13.5



More information about the mesa-dev mailing list