static gpointer
g_thread_pool_wait_for_new_task (GRealThreadPool *pool)
{
  gpointer task = NULL;

  if (pool->running || (!pool->immediate &&
			g_async_queue_length_unlocked (pool->queue) > 0))
    {
      /* This thread pool is still active. */
      if (pool->num_threads > pool->max_threads && pool->max_threads != -1)
	{
	  /* This is a superfluous thread, so it goes to the global pool. */
	  DEBUG_MSG (("superfluous thread %p in pool %p.",
		      g_thread_self (), pool));
	}
      else if (pool->pool.exclusive)
	{
	  /* Exclusive threads stay attached to the pool. */
	  task = g_async_queue_pop_unlocked (pool->queue);

	  DEBUG_MSG (("thread %p in exclusive pool %p waits for task "
		      "(%d running, %d unprocessed).",
		      g_thread_self (), pool, pool->num_threads,
		      g_async_queue_length_unlocked (pool->queue)));
	}
      else
	{
	  /* A thread will wait for new tasks for at most 1/2
	   * second before going to the global pool.
	   */
	  GTimeVal end_time;

	  g_get_current_time (&end_time);
	  g_time_val_add (&end_time, G_USEC_PER_SEC / 2);	/* 1/2 second */

	  DEBUG_MSG (("thread %p in pool %p waits for up to a 1/2 second for task "
		      "(%d running, %d unprocessed).",
		      g_thread_self (), pool, pool->num_threads,
		      g_async_queue_length_unlocked (pool->queue)));

	  task = g_async_queue_timed_pop_unlocked (pool->queue, &end_time);
	}
    }
  else
    {
      /* This thread pool is inactive, it will no longer process tasks. */
      DEBUG_MSG (("pool %p not active, thread %p will go to global pool "
		  "(running: %s, immediate: %s, len: %d).",
		  pool, g_thread_self (),
		  pool->running ? "true" : "false",
		  pool->immediate ? "true" : "false",
		  g_async_queue_length_unlocked (pool->queue)));
    }

  return task;
}
示例#2
0
文件: iris-queue.c 项目: antono/iris
static gpointer
iris_queue_real_timed_pop_or_close (IrisQueue *queue,
                                    GTimeVal  *timeout)
{
	gpointer item;

	g_async_queue_lock (queue->priv->q);
	item = g_async_queue_timed_pop_unlocked (queue->priv->q, timeout);

	if (g_atomic_int_get (&queue->priv->open) == FALSE)
		item = handle_close_token_ul (queue, item);
	else if (item == NULL)
		close_ul (queue);
	g_async_queue_unlock (queue->priv->q);

	return item;
}
示例#3
0
文件: iris-queue.c 项目: antono/iris
static gpointer
iris_queue_real_timed_pop (IrisQueue *queue,
                           GTimeVal  *timeout)
{
	gpointer item;

	g_async_queue_lock (queue->priv->q);
	if (g_atomic_int_get (&queue->priv->open) == FALSE &&
	    g_async_queue_length_unlocked (queue->priv->q) <= 0) {
		g_async_queue_unlock (queue->priv->q);
		return NULL;
	}

	item = g_async_queue_timed_pop_unlocked (queue->priv->q, timeout);

	if (g_atomic_int_get (&queue->priv->open) == FALSE)
		item = handle_close_token_ul (queue, item);
	g_async_queue_unlock (queue->priv->q);

	return item;
}