Subsurf: Use regular mutex instead of RW one
authorSergey Sharybin <sergey.vfx@gmail.com>
Thu, 11 Jan 2018 13:32:56 +0000 (14:32 +0100)
committerSergey Sharybin <sergey.vfx@gmail.com>
Thu, 11 Jan 2018 13:38:58 +0000 (14:38 +0100)
Mutex is now local to particular CCGDM, and guarding edge hash which is only
used by a single function only. There is no need to acquire read lock after
edge hash was created.

source/blender/blenkernel/BKE_subsurf.h
source/blender/blenkernel/intern/subsurf_ccg.c

index d7b9d20d7b0994cc93fbaa841a86e3e581f1f5de..96320415b16164d3b22134f107f82961a8fa5882 100644 (file)
@@ -144,7 +144,7 @@ typedef struct CCGDerivedMesh {
 
        struct EdgeHash *ehash;
 
-       ThreadRWMutex loops_cache_rwlock;
+       ThreadMutex loops_cache_lock;
        ThreadRWMutex origindex_cache_rwlock;
 } CCGDerivedMesh;
 
index d2f325fb3c4d0e22fec4fb3ae1fc5406a5da0de5..c6b701d2d287a1360f267dd318304d810f0a31ad 100644 (file)
@@ -1488,7 +1488,7 @@ static void ccgDM_copyFinalLoopArray(DerivedMesh *dm, MLoop *mloop)
        /* DMFlagMat *faceFlags = ccgdm->faceFlags; */ /* UNUSED */
 
        if (!ccgdm->ehash) {
-               BLI_rw_mutex_lock(&ccgdm->loops_cache_rwlock, THREAD_LOCK_WRITE);
+               BLI_mutex_lock(&ccgdm->loops_cache_lock);
                if (!ccgdm->ehash) {
                        MEdge *medge;
                        EdgeHash *ehash;
@@ -1502,10 +1502,9 @@ static void ccgDM_copyFinalLoopArray(DerivedMesh *dm, MLoop *mloop)
 
                        atomic_cas_ptr((void**)&ccgdm->ehash, ccgdm->ehash, ehash);
                }
-               BLI_rw_mutex_unlock(&ccgdm->loops_cache_rwlock);
+               BLI_mutex_unlock(&ccgdm->loops_cache_lock);
        }
 
-       BLI_rw_mutex_lock(&ccgdm->loops_cache_rwlock, THREAD_LOCK_READ);
        totface = ccgSubSurf_getNumFaces(ss);
        ml = mloop;
        for (index = 0; index < totface; index++) {
@@ -1548,7 +1547,6 @@ static void ccgDM_copyFinalLoopArray(DerivedMesh *dm, MLoop *mloop)
                        }
                }
        }
-       BLI_rw_mutex_unlock(&ccgdm->loops_cache_rwlock);
 }
 
 static void ccgDM_copyFinalPolyArray(DerivedMesh *dm, MPoly *mpoly)
@@ -4050,7 +4048,7 @@ static void ccgDM_release(DerivedMesh *dm)
                        MEM_freeN(ccgdm->faceMap);
                }
 
-               BLI_rw_mutex_end(&ccgdm->loops_cache_rwlock);
+               BLI_mutex_end(&ccgdm->loops_cache_lock);
                BLI_rw_mutex_end(&ccgdm->origindex_cache_rwlock);
 
                MEM_freeN(ccgdm);
@@ -5044,7 +5042,7 @@ static CCGDerivedMesh *getCCGDerivedMesh(CCGSubSurf *ss,
        ccgdm->dm.numLoopData = ccgdm->dm.numPolyData * 4;
        ccgdm->dm.numTessFaceData = 0;
 
-       BLI_rw_mutex_init(&ccgdm->loops_cache_rwlock);
+       BLI_mutex_init(&ccgdm->loops_cache_lock);
        BLI_rw_mutex_init(&ccgdm->origindex_cache_rwlock);
 
        return ccgdm;