Example #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);
}
Example #2
0
static void *
thread_loop (void *args)
{
  struct thread_pool *pool = args;
  struct work_unit *work;

  while (NULL != (work = async_queue_pop (pool->work_queue, true)))
    {
      if (THREAD_POOL_TERM_SIG == work->func)
        {
          pthread_mutex_lock (&pool->lock);

          if (1 < pool->num_threads)
            thread_pool_push (pool, THREAD_POOL_TERM_SIG, NULL);

          pool->num_threads--;

          pthread_mutex_unlock (&pool->lock);
          free (work);

          return NULL;
        }

      work->func (work->data);

      free (work);
    }

  return NULL;
}
Example #3
0
void*
worker(void *arg)
{
    ctx_t  *ctx;
    task_t *task;

    ERL_NIF_TERM result;

    ctx = static_cast<ctx_t*>(arg);

    while (true) {
        task = static_cast<task_t*>(async_queue_pop(ctx->queue));

        if (task->type == COMPRESS) {
            result = compress(task);
        } else if (task->type == DECOMPRESS) {
            result = decompress(task);
        } else if (task->type == SHUTDOWN) {
            break;
        } else {
            errx(1, "Unexpected task type: %i", task->type);
        }

        enif_send(NULL, &task->pid, task->env, result);
        cleanup_task(&task);
    }

    cleanup_task(&task);
    return NULL;
}
Example #4
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);
}
Example #5
0
static gpointer
pop_func (gpointer data)
{
    AsyncQueue *queue;
    gpointer foo;
    guint i;

    queue = data;
    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");
    }

    return NULL;
}
Example #6
0
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);
}
Example #7
0
static gpointer
pop_with_disable_func (gpointer data)
{
    AsyncQueue *queue;
    gpointer foo;
    guint i;
    guint count = 0;

    queue = data;
    foo = GINT_TO_POINTER (1);
    for (i = 0; i < PROCESS_COUNT; i++, foo++)
    {
        gpointer tmp;
        tmp = async_queue_pop (queue);
        if (!tmp)
            continue;
        count++;
        fail_if (tmp != foo,
                 "Pop failed");
    }

    return GINT_TO_POINTER (count);
}
Example #8
0
OMX_BUFFERHEADERTYPE *
g_omx_port_request_buffer (GOmxPort *port)
{
    return async_queue_pop (port->queue);
}