[Bf-blender-cvs] [1d8aebaa096] master: Add an 'atomic cas' wrapper for pointers.

Bastien Montagne noreply at git.blender.org
Mon Sep 25 10:42:13 CEST 2017


Commit: 1d8aebaa096fd5afc758a88f99862e74b5d6c7e0
Author: Bastien Montagne
Date:   Mon Sep 25 10:40:50 2017 +0200
Branches: master
https://developer.blender.org/rB1d8aebaa096fd5afc758a88f99862e74b5d6c7e0

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
M	source/blender/blenkernel/intern/cdderivedmesh.c
M	source/blender/blenkernel/intern/editderivedmesh.c
M	source/blender/blenkernel/intern/subsurf_ccg.c

===================================================================

diff --git a/intern/atomic/atomic_ops.h b/intern/atomic/atomic_ops.h
index 72813c39ac2..38670be56fd 100644
--- a/intern/atomic/atomic_ops.h
+++ b/intern/atomic/atomic_ops.h
@@ -108,6 +108,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 8d5f2e5dad7..34158a0b45e 100644
--- a/intern/atomic/intern/atomic_ops_ext.h
+++ b/intern/atomic/intern/atomic_ops_ext.h
@@ -180,6 +180,18 @@ ATOMIC_INLINE unsigned int atomic_cas_u(unsigned int *v, unsigned int old, unsig
 }
 
 /******************************************************************************/
+/* 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. */
 
 ATOMIC_INLINE float atomic_add_and_fetch_fl(float *p, const float x)
diff --git a/source/blender/blenkernel/intern/cdderivedmesh.c b/source/blender/blenkernel/intern/cdderivedmesh.c
index 4d94ebfed77..2c61cf28691 100644
--- a/source/blender/blenkernel/intern/cdderivedmesh.c
+++ b/source/blender/blenkernel/intern/cdderivedmesh.c
@@ -1930,7 +1930,7 @@ void CDDM_recalc_looptri(DerivedMesh *dm)
 	        cddm->dm.looptris.array_wip);
 
 	BLI_assert(cddm->dm.looptris.array == NULL);
-	atomic_cas_z((size_t *)&cddm->dm.looptris.array, *(size_t *)&cddm->dm.looptris.array, *(size_t *)&cddm->dm.looptris.array_wip);
+	atomic_cas_ptr((void **)&cddm->dm.looptris.array, cddm->dm.looptris.array, cddm->dm.looptris.array_wip);
 	cddm->dm.looptris.array_wip = NULL;
 }
 
diff --git a/source/blender/blenkernel/intern/editderivedmesh.c b/source/blender/blenkernel/intern/editderivedmesh.c
index 357420179dd..d810dac7365 100644
--- a/source/blender/blenkernel/intern/editderivedmesh.c
+++ b/source/blender/blenkernel/intern/editderivedmesh.c
@@ -664,7 +664,7 @@ static void emDM_recalcLoopTri(DerivedMesh *dm)
 	}
 
 	BLI_assert(dm->looptris.array == NULL);
-	atomic_cas_z((size_t *)&dm->looptris.array, *(size_t *)&dm->looptris.array, *(size_t *)&dm->looptris.array_wip);
+	atomic_cas_ptr((void **)&dm->looptris.array, dm->looptris.array, dm->looptris.array_wip);
 	dm->looptris.array_wip = NULL;
 }
 
diff --git a/source/blender/blenkernel/intern/subsurf_ccg.c b/source/blender/blenkernel/intern/subsurf_ccg.c
index c580c04e0df..f4ff4dfa019 100644
--- a/source/blender/blenkernel/intern/subsurf_ccg.c
+++ b/source/blender/blenkernel/intern/subsurf_ccg.c
@@ -4507,7 +4507,7 @@ static void ccgDM_recalcLoopTri(DerivedMesh *dm)
 	}
 
 	BLI_assert(dm->looptris.array == NULL);
-	atomic_cas_z((size_t *)&dm->looptris.array, *(size_t *)&dm->looptris.array, *(size_t *)&dm->looptris.array_wip);
+	atomic_cas_ptr((void **)&dm->looptris.array, dm->looptris.array, dm->looptris.array_wip);
 	dm->looptris.array_wip = NULL;
 }



More information about the Bf-blender-cvs mailing list