示例#1
0
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);
}
示例#2
0
bool
thread_pool_push (struct thread_pool *pool,
                  void(*func)(void *data),
                  void *data)
{
  struct work_unit *work = malloc (sizeof *work);
  work->func = func,
  work->data = data;

  return async_queue_push (pool->work_queue, work);
}
示例#3
0
void
resource_dtor(ErlNifEnv *env, void *obj)
{
    ctx_t  *ctx = static_cast<ctx_t*>(obj);
    task_t *task = init_empty_task(SHUTDOWN);
    void   *result = NULL;

    async_queue_push(ctx->queue, static_cast<void*>(task));
    enif_thread_join(ctx->tid, &result);
    async_queue_destroy(ctx->queue);
    enif_thread_opts_destroy(ctx->topts);
}
示例#4
0
ERL_NIF_TERM
snappy_decompress_impl(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[])
{
    ctx_t  *ctx;
    task_t *task;

    ErlNifPid pid;

    if (argc != 4) {
        return enif_make_badarg(env);
    }

    if (!enif_get_resource(env, argv[0], res_type,
            reinterpret_cast<void**>(&ctx))) {
        return enif_make_badarg(env);
    }

    if (!enif_is_ref(env, argv[1])) {
        return enif_make_tuple2(env, atom_error,
            enif_make_string(env, "Second arg. is not a reference",
                ERL_NIF_LATIN1));
    }

    if (!enif_get_local_pid(env, argv[2], &pid)) {
        return enif_make_tuple2(env, atom_error,
            enif_make_string(env, "Third arg. is not a pid of local process",
                ERL_NIF_LATIN1));
    }

    if (!enif_is_binary(env, argv[3])) {
        return enif_make_tuple2(env, atom_error,
            enif_make_string(env, "Forth arg. is not a binary",
                ERL_NIF_LATIN1));
    }

    task = init_task(DECOMPRESS, argv[1], pid, argv[3]);

    if (!task) {
        return enif_make_tuple2(env, atom_error,
            enif_make_string(env, "Failed to create a task",
                ERL_NIF_LATIN1));
    }

    async_queue_push(ctx->queue, static_cast<void*>(task));

    return atom_ok;
}
示例#5
0
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);
}
示例#6
0
END_TEST

static gpointer
push_func (gpointer data)
{
    AsyncQueue *queue;
    gpointer foo;
    guint i;

    queue = data;
    foo = GINT_TO_POINTER (1);
    for (i = 0; i < PROCESS_COUNT; i++, foo++)
    {
        async_queue_push (queue, foo);
    }

    return NULL;
}
示例#7
0
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;
}
示例#8
0
END_TEST

static gpointer
push_and_disable_func (gpointer data)
{
    AsyncQueue *queue;
    gpointer foo;
    guint i;

    queue = data;
    foo = GINT_TO_POINTER (1);
    for (i = 0; i < DISABLE_AT; i++, foo++)
    {
        async_queue_push (queue, foo);
    }

    async_queue_disable (queue);

    return NULL;
}
示例#9
0
void
g_omx_port_push_buffer (GOmxPort *port,
                        OMX_BUFFERHEADERTYPE *omx_buffer)
{
    async_queue_push (port->queue, omx_buffer);
}