pthread_mutex_lock (&bufmgr->lock);
- bo_handle = bufmgr->backend->bo_map (bo, device, opt);
+ bo_handle = bufmgr->backend->bo_get_handle (bo, device);
_tbm_bo_lock (bo, device, opt);
+ bo_handle = bufmgr->backend->bo_map (bo, device, opt);
+
if (bufmgr->use_map_cache == 1 && bo->map_cnt == 0)
_tbm_bo_set_state (bo, device, opt);
pthread_mutex_lock (&bufmgr->lock);
- _tbm_bo_unlock (bo);
ret = bufmgr->backend->bo_unmap (bo);
if (bo->map_cnt == 0)
_tbm_bo_save_state (bo);
+ _tbm_bo_unlock (bo);
+
pthread_mutex_unlock (&bufmgr->lock);
return ret;