#define DIRTY_QUEUE 2
#define NODE_LIST 4
-static tbm_bufmgr g_surf_queue_bufmgr;
+#define TBM_SURFACE_QUEUE_MAGIC 0xBF031234
+
static pthread_mutex_t tbm_surf_queue_lock = PTHREAD_MUTEX_INITIALIZER;
void _tbm_surface_queue_mutex_unlock(void);
} tbm_surface_queue_interface;
struct _tbm_surface_queue {
+ unsigned int magic;
int width;
int height;
int format;
tbm_surface_free_cb free_cb;
void *alloc_cb_data;
- struct list_head item_link; /* link of surface queue */
-
int modes;
unsigned int enqueue_sync_count;
unsigned int acquire_sync_count;
pthread_mutex_unlock(&tbm_surf_queue_lock);
}
-static void
-_init_tbm_surf_queue_bufmgr(void)
-{
- g_surf_queue_bufmgr = tbm_bufmgr_init(-1);
-}
-
-static void
-_deinit_tbm_surf_queue_bufmgr(void)
+static int
+_tbm_surface_queue_magic_check(tbm_surface_queue_h surface_queue)
{
- if (!g_surf_queue_bufmgr)
- return;
+ if (surface_queue->magic != TBM_SURFACE_QUEUE_MAGIC)
+ return 0;
- tbm_bufmgr_deinit(g_surf_queue_bufmgr);
- g_surf_queue_bufmgr = NULL;
+ return 1;
}
static int
_tbm_surface_queue_is_valid(tbm_surface_queue_h surface_queue)
{
- tbm_surface_queue_h old_data = NULL;
-
- if (surface_queue == NULL) {
+ if (!surface_queue) {
TBM_ERR("error: surface_queue is NULL.\n");
return 0;
}
- if (g_surf_queue_bufmgr == NULL) {
- TBM_ERR("error: g_surf_queue_bufmgr is NULL.\n");
- return 0;
- }
-
- if (LIST_IS_EMPTY(&g_surf_queue_bufmgr->surf_queue_list)) {
- TBM_ERR("error: surf_queue_list is empty\n");
+ if (!_tbm_surface_queue_magic_check(surface_queue)) {
+ TBM_ERR("error: Invalid tbm_surface_queue(%p)\n", surface_queue);
return 0;
}
- LIST_FOR_EACH_ENTRY(old_data, &g_surf_queue_bufmgr->surf_queue_list,
- item_link) {
- if (old_data == surface_queue)
- return 1;
- }
-
- TBM_ERR("error: Invalid tbm_surface_queue(%p)\n", surface_queue);
-
- return 0;
+ return 1;
}
static queue_node *
TBM_RETURN_IF_FAIL(surface_queue != NULL);
TBM_RETURN_IF_FAIL(impl != NULL);
- if (!g_surf_queue_bufmgr)
- _init_tbm_surf_queue_bufmgr();
-
pthread_mutex_init(&surface_queue->lock, NULL);
pthread_condattr_init(&free_attr);
pthread_cond_init(&surface_queue->dirty_cond, &dirty_attr);
pthread_condattr_destroy(&dirty_attr);
+ surface_queue->magic = TBM_SURFACE_QUEUE_MAGIC;
surface_queue->queue_size = queue_size;
surface_queue->width = width;
surface_queue->height = height;
if (surface_queue->impl && surface_queue->impl->init)
surface_queue->impl->init(surface_queue);
-
- LIST_ADD(&surface_queue->item_link, &g_surf_queue_bufmgr->surf_queue_list);
}
tbm_surface_queue_error_e
TBM_TRACE_SURFACE_QUEUE("tbm_surface_queue(%p)\n", surface_queue);
- LIST_DEL(&surface_queue->item_link);
+ surface_queue->magic = 0;
LIST_FOR_EACH_ENTRY_SAFE(node, tmp, &surface_queue->list, link)
_queue_delete_node(surface_queue, node);
free(surface_queue);
- if (LIST_IS_EMPTY(&g_surf_queue_bufmgr->surf_queue_list))
- _deinit_tbm_surf_queue_bufmgr();
-
_tbm_surf_queue_mutex_unlock();
}