Changeset View
Changeset View
Standalone View
Standalone View
source/blender/blenkernel/intern/mesh_runtime.c
| Show All 37 Lines | |||||
| #include "BKE_mesh_runtime.h" | #include "BKE_mesh_runtime.h" | ||||
| #include "BKE_shrinkwrap.h" | #include "BKE_shrinkwrap.h" | ||||
| #include "BKE_subdiv_ccg.h" | #include "BKE_subdiv_ccg.h" | ||||
| /* -------------------------------------------------------------------- */ | /* -------------------------------------------------------------------- */ | ||||
| /** \name Mesh Runtime Struct Utils | /** \name Mesh Runtime Struct Utils | ||||
| * \{ */ | * \{ */ | ||||
| static ThreadRWMutex loops_cache_lock = PTHREAD_RWLOCK_INITIALIZER; | |||||
| /** | /** | ||||
| * Default values defined at read time. | * Default values defined at read time. | ||||
| */ | */ | ||||
| void BKE_mesh_runtime_reset(Mesh *mesh) | void BKE_mesh_runtime_reset(Mesh *mesh) | ||||
| { | { | ||||
| memset(&mesh->runtime, 0, sizeof(mesh->runtime)); | memset(&mesh->runtime, 0, sizeof(mesh->runtime)); | ||||
| mesh->runtime.eval_mutex = MEM_mallocN(sizeof(ThreadMutex), "mesh runtime eval_mutex"); | mesh->runtime.eval_mutex = MEM_mallocN(sizeof(ThreadMutex), "mesh runtime eval_mutex"); | ||||
| BLI_mutex_init(mesh->runtime.eval_mutex); | BLI_mutex_init(mesh->runtime.eval_mutex); | ||||
| ▲ Show 20 Lines • Show All 98 Lines • ▼ Show 20 Lines | int BKE_mesh_runtime_looptri_len(const Mesh *mesh) | ||||
| return looptri_len; | return looptri_len; | ||||
| } | } | ||||
| /* This is a ported copy of dm_getLoopTriArray(dm). */ | /* This is a ported copy of dm_getLoopTriArray(dm). */ | ||||
| const MLoopTri *BKE_mesh_runtime_looptri_ensure(Mesh *mesh) | const MLoopTri *BKE_mesh_runtime_looptri_ensure(Mesh *mesh) | ||||
| { | { | ||||
| MLoopTri *looptri; | MLoopTri *looptri; | ||||
| BLI_rw_mutex_lock(&loops_cache_lock, THREAD_LOCK_READ); | ThreadMutex *mesh_eval_mutex = (ThreadMutex *)mesh->runtime.eval_mutex; | ||||
| BLI_mutex_lock(mesh_eval_mutex); | |||||
| looptri = mesh->runtime.looptris.array; | looptri = mesh->runtime.looptris.array; | ||||
| BLI_rw_mutex_unlock(&loops_cache_lock); | |||||
| if (looptri != NULL) { | if (looptri != NULL) { | ||||
| BLI_assert(BKE_mesh_runtime_looptri_len(mesh) == mesh->runtime.looptris.len); | BLI_assert(BKE_mesh_runtime_looptri_len(mesh) == mesh->runtime.looptris.len); | ||||
| } | } | ||||
| else { | else { | ||||
| BLI_rw_mutex_lock(&loops_cache_lock, THREAD_LOCK_WRITE); | |||||
| /* We need to ensure array is still NULL inside mutex-protected code, | |||||
| * some other thread might have already recomputed those looptris. */ | |||||
| if (mesh->runtime.looptris.array == NULL) { | |||||
| BKE_mesh_runtime_looptri_recalc(mesh); | BKE_mesh_runtime_looptri_recalc(mesh); | ||||
| } | |||||
| looptri = mesh->runtime.looptris.array; | looptri = mesh->runtime.looptris.array; | ||||
| BLI_rw_mutex_unlock(&loops_cache_lock); | |||||
| } | } | ||||
| BLI_mutex_unlock(mesh_eval_mutex); | |||||
sergey: This is some weird residue of the double-checked-lock patter.
Either follow the pattern ,or… | |||||
| return looptri; | return looptri; | ||||
| } | } | ||||
| /* This is a copy of DM_verttri_from_looptri(). */ | /* This is a copy of DM_verttri_from_looptri(). */ | ||||
| void BKE_mesh_runtime_verttri_from_looptri(MVertTri *r_verttri, | void BKE_mesh_runtime_verttri_from_looptri(MVertTri *r_verttri, | ||||
| const MLoop *mloop, | const MLoop *mloop, | ||||
| const MLoopTri *looptri, | const MLoopTri *looptri, | ||||
| int looptri_num) | int looptri_num) | ||||
| ▲ Show 20 Lines • Show All 262 Lines • Show Last 20 Lines | |||||
This is some weird residue of the double-checked-lock patter.
Either follow the pattern ,or remove its reidue.