bo: use magic number for checking valid of bo
[platform/core/uifw/libtbm.git] / src / tbm_bo.c
index 7e190b1..527c30b 100644 (file)
@@ -34,6 +34,8 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 #include "tbm_bufmgr_int.h"
 #include "list.h"
 
+#define TBM_BO_MAGIC 0xBF011234
+
 /* check condition */
 #define TBM_BO_RETURN_IF_FAIL(cond) {\
        if (!(cond)) {\
@@ -280,35 +282,28 @@ _tbm_bo_unlock(tbm_bo bo)
 }
 
 static int
-_tbm_bo_is_valid(tbm_bo bo)
+_tbm_bo_magic_check(tbm_bo bo)
 {
-       tbm_bufmgr bufmgr = NULL;
-       tbm_bo old_data = NULL;
-
-       if (bo == NULL) {
-               TBM_ERR("error: bo is NULL.\n");
+       if (bo->magic != TBM_BO_MAGIC)
                return 0;
-       }
 
-       bufmgr = tbm_bufmgr_get();
-       if (bufmgr == NULL) {
-               TBM_ERR("error: bufmgr is NULL.\n");
-               return 0;
-       }
+       return 1;
+}
 
-       if (LIST_IS_EMPTY(&bufmgr->bo_list)) {
-               TBM_ERR("error: bo->bo->bufmgr->bo_list is EMPTY.\n");
+static int
+_tbm_bo_is_valid(tbm_bo bo)
+{
+       if (!bo) {
+               TBM_ERR("error: bo is NULL.\n");
                return 0;
        }
 
-       LIST_FOR_EACH_ENTRY(old_data, &bufmgr->bo_list, item_link) {
-               if (old_data == bo)
-                       return 1;
+       if (!_tbm_bo_magic_check(bo)) {
+               TBM_ERR("error: No valid bo(%p).\n", bo);
+               return 0;
        }
 
-       TBM_ERR("error: No valid bo(%p).\n", bo);
-
-       return 0;
+       return 1;
 }
 
 tbm_bo
@@ -369,6 +364,7 @@ tbm_bo_alloc(tbm_bufmgr bufmgr, int size, int flags)
        }
 
        bo->bufmgr->bo_cnt++;
+       bo->magic = TBM_BO_MAGIC;
        bo->ref_cnt = 1;
        bo->flags = flags;
 
@@ -774,6 +770,7 @@ tbm_bo_import(tbm_bufmgr bufmgr, unsigned int key)
        }
 
        bo->bufmgr->bo_cnt++;
+       bo->magic = TBM_BO_MAGIC;
        bo->ref_cnt = 1;
 
        if (bo->bufmgr->backend_module_data) {
@@ -903,6 +900,7 @@ tbm_bo_import_fd(tbm_bufmgr bufmgr, tbm_fd fd)
        }
 
        bo->bufmgr->bo_cnt++;
+       bo->magic = TBM_BO_MAGIC;
        bo->ref_cnt = 1;
 
        if (bo->bufmgr->backend_module_data) {
@@ -1246,6 +1244,7 @@ _tbm_bo_free(tbm_bo bo)
                bo->priv = NULL;
        }
 
+       bo->magic = 0;
        bo->bufmgr->bo_cnt--;
 
        LIST_DEL(&bo->item_link);