tbm_bufmgr: lock the gLock before locking tbm_bufmgr_mutex 66/260366/1
authorSooChan Lim <sc1.lim@samsung.com>
Thu, 24 Jun 2021 03:01:12 +0000 (12:01 +0900)
committerSooChan Lim <sc1.lim@samsung.com>
Thu, 24 Jun 2021 03:01:12 +0000 (12:01 +0900)
The order of locking mutex makes deadlock. So this patch
will start to fix.

Change-Id: Ic7b866eb5b6826239e1b671c059d0393c47ac4f1

src/tbm_bufmgr.c

index 6457f16..55f9243 100644 (file)
@@ -364,22 +364,22 @@ tbm_bufmgr_deinit(tbm_bufmgr bufmgr)
 {
        TBM_RETURN_IF_FAIL(TBM_BUFMGR_IS_VALID(bufmgr));
 
-       _tbm_bufmgr_mutex_lock();
        pthread_mutex_lock(&gLock);
+       _tbm_bufmgr_mutex_lock();
        _tbm_set_last_result(TBM_ERROR_NONE);
 
        if (!gBufMgr) {
                TBM_ERR("gBufmgr already destroy: bufmgr:%p\n", bufmgr);
-               pthread_mutex_unlock(&gLock);
                _tbm_bufmgr_mutex_unlock();
+               pthread_mutex_unlock(&gLock);
                return;
        }
 
        bufmgr->ref_count--;
        if (bufmgr->ref_count > 0) {
                TBM_DBG("reduce a ref_count(%d) of tbm_bufmgr(%p)\n", bufmgr->ref_count, bufmgr);
-               pthread_mutex_unlock(&gLock);
                _tbm_bufmgr_mutex_unlock();
+               pthread_mutex_unlock(&gLock);
                return;
        }
 
@@ -415,8 +415,8 @@ tbm_bufmgr_deinit(tbm_bufmgr bufmgr)
        free(bufmgr);
        gBufMgr = NULL;
 
-       pthread_mutex_unlock(&gLock);
        _tbm_bufmgr_mutex_unlock();
+       pthread_mutex_unlock(&gLock);
 }
 
 unsigned int