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); }
struct thread_pool * thread_pool_new (size_t max_threads) { struct thread_pool *pool = malloc (sizeof *pool); pool->work_queue = async_queue_new(), pool->thread_queue = async_queue_new(); pool->num_threads = max_threads; pthread_mutex_init (&pool->lock, NULL); while (max_threads--) { pthread_t *thread = malloc (sizeof *thread); pthread_create (thread, NULL, thread_loop, pool); async_queue_push (pool->thread_queue, thread); } return 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); }
GOmxPort * g_omx_port_new (GOmxCore *core) { GOmxPort *port; port = g_new0 (GOmxPort, 1); port->core = core; port->num_buffers = 0; port->buffer_size = 0; port->buffers = NULL; port->enabled = TRUE; port->queue = async_queue_new (); port->mutex = g_mutex_new (); return port; }