unlock bo untill lock_cnt is zero when free bo
[platform/core/uifw/libtbm.git] / src / tbm_bufmgr.c
index b27b6d3..d02dd41 100644 (file)
@@ -681,7 +681,7 @@ tbm_bufmgr_init(int fd)
 
 #ifdef TBM_BUFMGR_INIT_TIME
        /* get the end tv */
-       gettimeofday(&end_tv, NULL);
+       gettimeofday(&end_tv, NULL);
        TBM_LOG_I("tbm_bufmgr_init time: %ld ms", ((end_tv.tv_sec * 1000 + end_tv.tv_usec / 1000) - (start_tv.tv_sec * 1000 + start_tv.tv_usec / 1000)));
 #endif
 
@@ -824,10 +824,11 @@ tbm_bo_unref(tbm_bo bo)
                        }
                }
 
-               if (bo->lock_cnt > 0) {
+               while (bo->lock_cnt > 0) {
                        TBM_LOG_E("error lock_cnt:%d\n",
                                bo->lock_cnt);
                        _bo_unlock(bo);
+                       bo->lock_cnt--;
                }
 
                /* call the bo_free */
@@ -919,8 +920,6 @@ tbm_bo_import(tbm_bufmgr bufmgr, unsigned int key)
                return NULL;
        }
 
-       bufmgr->bo_cnt++;
-
        bo->bufmgr = bufmgr;
 
        bo_priv = bufmgr->backend->bo_import(bo, key);
@@ -945,6 +944,8 @@ tbm_bo_import(tbm_bufmgr bufmgr, unsigned int key)
                }
        }
 
+       bufmgr->bo_cnt++;
+
        bo->ref_cnt = 1;
        bo->priv = bo_priv;
 
@@ -992,8 +993,6 @@ tbm_bo_import_fd(tbm_bufmgr bufmgr, tbm_fd fd)
                return NULL;
        }
 
-       bufmgr->bo_cnt++;
-
        bo->bufmgr = bufmgr;
 
        bo_priv = bufmgr->backend->bo_import_fd(bo, fd);
@@ -1018,6 +1017,8 @@ tbm_bo_import_fd(tbm_bufmgr bufmgr, tbm_fd fd)
                }
        }
 
+       bufmgr->bo_cnt++;
+
        bo->ref_cnt = 1;
        bo->priv = bo_priv;
 
@@ -1531,7 +1532,7 @@ tbm_bufmgr_debug_show(tbm_bufmgr bufmgr)
                                TBM_DEBUG(" bo:%-12p  %-26d%-10d\n",
                                          surf->bos[i],
                                          surf->bos[i]->ref_cnt,
-                                         tbm_bo_size(surf->bos[i]) / 1024);
+                                         bufmgr->backend->bo_size(surf->bos[i]) / 1024);
                        }
 
                        memset(app_name, 0x0, 255 * sizeof(char));
@@ -1551,7 +1552,7 @@ tbm_bufmgr_debug_show(tbm_bufmgr bufmgr)
                                  ++bo_cnt,
                                  bo,
                                  bo->ref_cnt,
-                                 tbm_bo_size(bo) / 1024,
+                                 bufmgr->backend->bo_size(bo) / 1024,
                                  bo->lock_cnt,
                                  bo->map_cnt,
                                  bo->flags,