END_TEST START_TEST (test_async_queue_process) { AsyncQueue *queue; gpointer foo; guint i; queue = async_queue_new (); fail_if (!queue, "Construction failed"); foo = GINT_TO_POINTER (1); for (i = 0; i < PROCESS_COUNT; i++, foo++) { async_queue_push (queue, foo); } foo = GINT_TO_POINTER (1); for (i = 0; i < PROCESS_COUNT; i++, foo++) { gpointer tmp; tmp = async_queue_pop (queue); fail_if (tmp != foo, "Pop failed"); } async_queue_free (queue); }
END_TEST START_TEST (test_async_queue_enable) { AsyncQueue *queue; GThread *push_thread; GThread *pop_thread; guint count; queue = async_queue_new (); fail_if (!queue, "Construction failed"); pop_thread = g_thread_create (pop_with_disable_func, queue, TRUE, NULL); async_queue_disable (queue); count = GPOINTER_TO_INT (g_thread_join (pop_thread)); fail_if (count != 0, "Disable failed"); async_queue_enable (queue); pop_thread = g_thread_create (pop_with_disable_func, queue, TRUE, NULL); push_thread = g_thread_create (push_and_disable_func, queue, TRUE, NULL); count = GPOINTER_TO_INT (g_thread_join (pop_thread)); g_thread_join (push_thread); fail_if (count > DISABLE_AT, "Disable failed"); async_queue_free (queue); }
void async_queue_destroy(AsyncQueue *queue) { assert(queue != NULL); async_queue_free(queue); free(queue); }
void g_omx_port_free (GOmxPort *port) { g_mutex_free (port->mutex); async_queue_free (port->queue); g_free (port->buffers); g_free (port); }
void thread_pool_free (struct thread_pool *pool) { while (0 < async_queue_count (pool->thread_queue)) { pthread_t *thread = async_queue_pop (pool->thread_queue, true); pthread_join (*thread, NULL); free (thread); } assert (0 == async_queue_count (pool->work_queue)); async_queue_free (pool->work_queue); assert (0 == async_queue_count (pool->thread_queue)); async_queue_free (pool->thread_queue); pthread_mutex_destroy (&pool->lock); free (pool); }
END_TEST START_TEST (test_async_queue_pop) { AsyncQueue *queue; gpointer foo; gpointer tmp; queue = async_queue_new (); fail_if (!queue, "Construction failed"); foo = GINT_TO_POINTER (1); async_queue_push (queue, foo); tmp = async_queue_pop (queue); fail_if (tmp != foo, "Pop failed"); async_queue_free (queue); }
UAsyncQueue *async_queue_new(void) { UAsyncQueue *queue = malloc(sizeof(*queue)); if (!queue) return NULL; queue->queue = queue_new(); if (!queue->queue) goto error; if (pthread_cond_init(&queue->cond, NULL) != 0) goto error; pthread_mutex_init(&queue->mutex, NULL); queue->is_waiting = 0; return queue; error: async_queue_free(queue); return NULL; }