diff options
author | Bastien Montagne <montagne29@wanadoo.fr> | 2017-09-25 10:56:02 +0300 |
---|---|---|
committer | Bastien Montagne <montagne29@wanadoo.fr> | 2017-09-25 10:56:02 +0300 |
commit | 01a3c6b204bfbe149dc2cc2278dd58f206af7ae2 (patch) | |
tree | d997f65227966b031083bf50f60718513a6b0a36 /source/blender/blenkernel/intern/cdderivedmesh.c | |
parent | cb6f07f59e4045f4bc3d4c3f8e2bba681cc6bb79 (diff) |
Tweak to fix for thread concurency in looptri generation.
Even if pointer assignment may be atomic, it does not prevent reordering
and other nifty compiler tricks, we need a memory barrier to ensure not
only that transferring pointer from wip array to final one is atomic,
but also that all previous writing to memory are “flushed” to
(visible by) all CPUs...
Thanks @sergey for finding the potential (though quite unlikely) issue.
Diffstat (limited to 'source/blender/blenkernel/intern/cdderivedmesh.c')
-rw-r--r-- | source/blender/blenkernel/intern/cdderivedmesh.c | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/source/blender/blenkernel/intern/cdderivedmesh.c b/source/blender/blenkernel/intern/cdderivedmesh.c index 42ca4359a58..4d94ebfed77 100644 --- a/source/blender/blenkernel/intern/cdderivedmesh.c +++ b/source/blender/blenkernel/intern/cdderivedmesh.c @@ -34,6 +34,8 @@ * \ingroup bke */ +#include "atomic_ops.h" + #include "BLI_math.h" #include "BLI_edgehash.h" #include "BLI_utildefines.h" @@ -1928,7 +1930,8 @@ void CDDM_recalc_looptri(DerivedMesh *dm) cddm->dm.looptris.array_wip); BLI_assert(cddm->dm.looptris.array == NULL); - SWAP(MLoopTri *, cddm->dm.looptris.array, cddm->dm.looptris.array_wip); + atomic_cas_z((size_t *)&cddm->dm.looptris.array, *(size_t *)&cddm->dm.looptris.array, *(size_t *)&cddm->dm.looptris.array_wip); + cddm->dm.looptris.array_wip = NULL; } static void cdDM_free_internal(CDDerivedMesh *cddm) |