bufmgr: make tbm_bufmgr_bo_lock_type 75/170775/3
authorSooChan Lim <sc1.lim@samsung.com>
Thu, 22 Feb 2018 05:04:54 +0000 (14:04 +0900)
committerSooChan Lim <sc1.lim@samsung.com>
Thu, 22 Feb 2018 07:54:39 +0000 (07:54 +0000)
make the tbm_bufmgr_bo_lock_type and put it on tbm_bufmgr.h

Change-Id: Ic06c41ae59c7852e252c64ac4479fbf02273ea4b

src/tbm_bufmgr.c
src/tbm_bufmgr.h
src/tbm_bufmgr_int.h

index 03aaa9d..1dd4f13 100644 (file)
@@ -96,12 +96,6 @@ static void _tbm_bufmgr_mutex_unlock(void);
        } \
 }
 
-enum {
-       LOCK_TRY_ONCE,
-       LOCK_TRY_ALWAYS,
-       LOCK_TRY_NEVER
-};
-
 static void
 _tbm_set_last_result(tbm_error_e err)
 {
@@ -350,7 +344,7 @@ _tbm_bo_lock(tbm_bo bo, int device, int opt)
        bufmgr = bo->bufmgr;
 
        /* do not try to lock the bo */
-       if (bufmgr->lock_type == LOCK_TRY_NEVER)
+       if (bufmgr->bo_lock_type == TBM_BUFMGR_BO_LOCK_TYPE_NEVER)
                return 1;
 
        if (bo->lock_cnt < 0) {
@@ -361,8 +355,8 @@ _tbm_bo_lock(tbm_bo bo, int device, int opt)
 
        old = bo->lock_cnt;
 
-       switch (bufmgr->lock_type) {
-       case LOCK_TRY_ONCE:
+       switch (bufmgr->bo_lock_type) {
+       case TBM_BUFMGR_BO_LOCK_TYPE_ONCE:
                if (bo->lock_cnt == 0) {
                        _tbm_bufmgr_mutex_unlock();
                        ret = _bo_lock(bo, device, opt);
@@ -372,7 +366,7 @@ _tbm_bo_lock(tbm_bo bo, int device, int opt)
                } else
                        ret = 1;
                break;
-       case LOCK_TRY_ALWAYS:
+       case TBM_BUFMGR_BO_LOCK_TYPE_ALWAYS:
                _tbm_bufmgr_mutex_unlock();
                ret = _bo_lock(bo, device, opt);
                _tbm_bufmgr_mutex_lock();
@@ -380,8 +374,8 @@ _tbm_bo_lock(tbm_bo bo, int device, int opt)
                        bo->lock_cnt++;
                break;
        default:
-               TBM_LOG_E("error bo:%p lock_type[%d] is wrong.\n",
-                               bo, bufmgr->lock_type);
+               TBM_LOG_E("error bo:%p bo_lock_type[%d] is wrong.\n",
+                               bo, bufmgr->bo_lock_type);
                ret = 0;
                break;
        }
@@ -403,28 +397,28 @@ _tbm_bo_unlock(tbm_bo bo)
        bufmgr = bo->bufmgr;
 
        /* do not try to unlock the bo */
-       if (bufmgr->lock_type == LOCK_TRY_NEVER)
+       if (bufmgr->bo_lock_type == TBM_BUFMGR_BO_LOCK_TYPE_NEVER)
                return;
 
        old = bo->lock_cnt;
 
-       switch (bufmgr->lock_type) {
-       case LOCK_TRY_ONCE:
+       switch (bufmgr->bo_lock_type) {
+       case TBM_BUFMGR_BO_LOCK_TYPE_ONCE:
                if (bo->lock_cnt > 0) {
                        bo->lock_cnt--;
                        if (bo->lock_cnt == 0)
                                _bo_unlock(bo);
                }
                break;
-       case LOCK_TRY_ALWAYS:
+       case TBM_BUFMGR_BO_LOCK_TYPE_ALWAYS:
                if (bo->lock_cnt > 0) {
                        bo->lock_cnt--;
                        _bo_unlock(bo);
                }
                break;
        default:
-               TBM_LOG_E("error bo:%p lock_type[%d] is wrong.\n",
-                               bo, bufmgr->lock_type);
+               TBM_LOG_E("error bo:%p bo_lock_type[%d] is wrong.\n",
+                               bo, bufmgr->bo_lock_type);
                break;
        }
 
@@ -717,16 +711,16 @@ _tbm_bufmgr_init(int fd, int server)
        TBM_DBG("create tizen bufmgr:%p ref_count:%d\n",
            gBufMgr, gBufMgr->ref_count);
 
-       /* setup the lock_type */
+       /* setup the bo_lock_type */
        env = getenv("BUFMGR_LOCK_TYPE");
        if (env && !strcmp(env, "always"))
-               gBufMgr->lock_type = LOCK_TRY_ALWAYS;
+               gBufMgr->bo_lock_type = TBM_BUFMGR_BO_LOCK_TYPE_ALWAYS;
        else if (env && !strcmp(env, "none"))
-               gBufMgr->lock_type = LOCK_TRY_NEVER;
+               gBufMgr->bo_lock_type = TBM_BUFMGR_BO_LOCK_TYPE_NEVER;
        else if (env && !strcmp(env, "once"))
-               gBufMgr->lock_type = LOCK_TRY_ONCE;
+               gBufMgr->bo_lock_type = TBM_BUFMGR_BO_LOCK_TYPE_ONCE;
        else
-               gBufMgr->lock_type = LOCK_TRY_ALWAYS;
+               gBufMgr->bo_lock_type = TBM_BUFMGR_BO_LOCK_TYPE_ALWAYS;
 
        TBM_DBG("BUFMGR_LOCK_TYPE=%s\n", env ? env : "default:once");
 
@@ -1319,7 +1313,7 @@ tbm_bo_locked(tbm_bo bo)
        TBM_BUFMGR_RETURN_VAL_IF_FAIL(TBM_BUFMGR_IS_VALID(gBufMgr), 0);
        TBM_BUFMGR_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo), 0);
 
-       if (bufmgr->lock_type == LOCK_TRY_NEVER) {
+       if (bufmgr->bo_lock_type == TBM_BUFMGR_BO_LOCK_TYPE_NEVER) {
                TBM_LOG_E("bo(%p) lock_cnt(%d)\n", bo, bo->lock_cnt);
                _tbm_bufmgr_mutex_unlock();
                return 0;
index 0112312..867cb3e 100644 (file)
@@ -172,6 +172,16 @@ enum TBM_BUFMGR_CAPABILITY {
        TBM_BUFMGR_CAPABILITY_TBM_SYNC = (1 << 2),              /**< Support tbm sync */
 };
 
+/**
+ * @brief Enumeration of buffer manager lock try for bo
+ * @since_tizen 5.0
+ */
+typedef enum {
+       TBM_BUFMGR_BO_LOCK_TYPE_NEVER = 0,  /**< the bufmgr do not try to lock the bos when the tbm_bo_map is called. */
+       TBM_BUFMGR_BO_LOCK_TYPE_ONCE,       /**< the bufmgr tries to lock the bos only once when the tbm_bo_map is called. */
+       TBM_BUFMGR_BO_LOCK_TYPE_ALWAYS,     /**< the bufmgr always tries to lock the bos when the tbm_bo_map is called. */
+} tbm_bufmgr_bo_lock_type;
+
 #ifdef __cplusplus
 extern "C" {
 #endif
index fc427cb..d940449 100644 (file)
@@ -241,7 +241,7 @@ struct _tbm_bufmgr {
        pthread_mutex_t lock;             /* mutex lock */
        int ref_count;                    /* reference count */
        int fd;                           /* bufmgr fd */
-       int lock_type;                    /* lock_type of bufmgr */
+       tbm_bufmgr_bo_lock_type bo_lock_type;  /* lock_type of bufmgr */
        int capabilities;                 /* capabilities of bufmgr */
        unsigned int bo_cnt;              /* number of bos */
        struct list_head bo_list;         /* list of bos belonging to bufmgr */