Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBastien Montagne <montagne29@wanadoo.fr>2017-09-25 10:56:02 +0300
committerBastien Montagne <montagne29@wanadoo.fr>2017-09-25 10:56:02 +0300
commit01a3c6b204bfbe149dc2cc2278dd58f206af7ae2 (patch)
treed997f65227966b031083bf50f60718513a6b0a36
parentcb6f07f59e4045f4bc3d4c3f8e2bba681cc6bb79 (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.
-rw-r--r--source/blender/blenkernel/intern/cdderivedmesh.c5
-rw-r--r--source/blender/blenkernel/intern/editderivedmesh.c5
-rw-r--r--source/blender/blenkernel/intern/subsurf_ccg.c5
3 files changed, 12 insertions, 3 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)
diff --git a/source/blender/blenkernel/intern/editderivedmesh.c b/source/blender/blenkernel/intern/editderivedmesh.c
index 9f688432988..357420179dd 100644
--- a/source/blender/blenkernel/intern/editderivedmesh.c
+++ b/source/blender/blenkernel/intern/editderivedmesh.c
@@ -41,6 +41,8 @@
* is likely to be a little slow.
*/
+#include "atomic_ops.h"
+
#include "BLI_math.h"
#include "BLI_jitter.h"
#include "BLI_bitmap.h"
@@ -662,7 +664,8 @@ static void emDM_recalcLoopTri(DerivedMesh *dm)
}
BLI_assert(dm->looptris.array == NULL);
- SWAP(MLoopTri *, dm->looptris.array, dm->looptris.array_wip);
+ atomic_cas_z((size_t *)&dm->looptris.array, *(size_t *)&dm->looptris.array, *(size_t *)&dm->looptris.array_wip);
+ dm->looptris.array_wip = NULL;
}
static void emDM_foreachMappedVert(
diff --git a/source/blender/blenkernel/intern/subsurf_ccg.c b/source/blender/blenkernel/intern/subsurf_ccg.c
index 27bbdf228d4..c580c04e0df 100644
--- a/source/blender/blenkernel/intern/subsurf_ccg.c
+++ b/source/blender/blenkernel/intern/subsurf_ccg.c
@@ -42,6 +42,8 @@
#include <math.h>
#include <float.h>
+#include "atomic_ops.h"
+
#include "MEM_guardedalloc.h"
#include "DNA_mesh_types.h"
@@ -4505,7 +4507,8 @@ static void ccgDM_recalcLoopTri(DerivedMesh *dm)
}
BLI_assert(dm->looptris.array == NULL);
- SWAP(MLoopTri *, dm->looptris.array, dm->looptris.array_wip);
+ atomic_cas_z((size_t *)&dm->looptris.array, *(size_t *)&dm->looptris.array, *(size_t *)&dm->looptris.array_wip);
+ dm->looptris.array_wip = NULL;
}
static void ccgDM_calcNormals(DerivedMesh *dm)