[Bf-blender-cvs] [e4e2e3a15db] blender-v2.79a-release: Add an 'atomic cas' wrapper for pointers.
Bastien Montagne
noreply at git.blender.org
Tue Jan 9 14:28:07 CET 2018
Commit: e4e2e3a15db571b97b3acb005d9fcf30261d2bf2
Author: Bastien Montagne
Date: Mon Sep 25 10:40:50 2017 +0200
Branches: blender-v2.79a-release
https://developer.blender.org/rBe4e2e3a15db571b97b3acb005d9fcf30261d2bf2
Add an 'atomic cas' wrapper for pointers.
Avoids having to repeat obfuscating castings everywhere...
===================================================================
M intern/atomic/atomic_ops.h
M intern/atomic/intern/atomic_ops_ext.h
===================================================================
diff --git a/intern/atomic/atomic_ops.h b/intern/atomic/atomic_ops.h
index 1e9528f9ed9..683ced7a72f 100644
--- a/intern/atomic/atomic_ops.h
+++ b/intern/atomic/atomic_ops.h
@@ -107,6 +107,8 @@ ATOMIC_INLINE unsigned int atomic_fetch_and_add_u(unsigned int *p, unsigned int
ATOMIC_INLINE unsigned int atomic_fetch_and_sub_u(unsigned int *p, unsigned int x);
ATOMIC_INLINE unsigned int atomic_cas_u(unsigned int *v, unsigned int old, unsigned int _new);
+ATOMIC_INLINE void *atomic_cas_ptr(void **v, void *old, void *_new);
+
/* WARNING! Float 'atomics' are really faked ones, those are actually closer to some kind of spinlock-sync'ed operation,
* which means they are only efficient if collisions are highly unlikely (i.e. if probability of two threads
* working on the same pointer at the same time is very low). */
diff --git a/intern/atomic/intern/atomic_ops_ext.h b/intern/atomic/intern/atomic_ops_ext.h
index b72c94563fc..930c961bd3d 100644
--- a/intern/atomic/intern/atomic_ops_ext.h
+++ b/intern/atomic/intern/atomic_ops_ext.h
@@ -168,6 +168,18 @@ ATOMIC_INLINE unsigned int atomic_cas_u(unsigned int *v, unsigned int old, unsig
#endif
}
+/******************************************************************************/
+/* Pointer operations. */
+
+ATOMIC_INLINE void *atomic_cas_ptr(void **v, void *old, void *_new)
+{
+#if (LG_SIZEOF_PTR == 8)
+ return (void *)atomic_cas_uint64((uint64_t *)v, *(uint64_t *)&old, *(uint64_t *)&_new);
+#elif (LG_SIZEOF_PTR == 4)
+ return (void *)atomic_cas_uint32((uint32_t *)v, *(uint32_t *)&old, *(uint32_t *)&_new);
+#endif
+}
+
/******************************************************************************/
/* float operations. */
More information about the Bf-blender-cvs
mailing list