static void
test_thread_sort (gboolean sort)
{
  GThreadPool *pool;
  guint limit;
  guint max_threads;
  gint i;

  limit = MAX_THREADS * 10;

  if (sort) {
    max_threads = 1;
  } else {
    max_threads = MAX_THREADS;
  }

  /* It is important that we only have a maximum of 1 thread for this
   * test since the results can not be guranteed to be sorted if > 1.
   * 
   * Threads are scheduled by the operating system and are executed at
   * random. It cannot be assumed that threads are executed in the
   * order they are created. This was discussed in bug #334943.
   */
  
  pool = g_thread_pool_new (test_thread_sort_entry_func, 
			    GINT_TO_POINTER (sort), 
			    max_threads, 
			    FALSE,
			    NULL);

  g_thread_pool_set_max_unused_threads (MAX_UNUSED_THREADS); 

  if (sort) {
    g_thread_pool_set_sort_function (pool, 
				     test_thread_sort_compare_func,
				     GUINT_TO_POINTER (69));
  }
  
  for (i = 0; i < limit; i++) {
    guint id;

    id = g_random_int_range (1, limit) + 1;
    g_thread_pool_push (pool, GUINT_TO_POINTER (id), NULL);
    DEBUG_MSG (("%s ===> pushed new thread with id:%d, number "
		"of threads:%d, unprocessed:%d",
		sort ? "[  sorted]" : "[unsorted]", 
		id, 
		g_thread_pool_get_num_threads (pool),
		g_thread_pool_unprocessed (pool)));
  }

  g_assert (g_thread_pool_get_max_threads (pool) == max_threads);
  g_assert (g_thread_pool_get_num_threads (pool) == g_thread_pool_get_max_threads (pool));
}
Exemplo n.º 2
0
static void sigusr1_cb(struct ev_loop *loop, ev_signal *w, int revents)
{
	struct emc_server_context *ctx = w->data;

log_printf(DEBUG_LEVEL_INFO, "INFO signal SIGUSR1 caught");
log_printf(DEBUG_LEVEL_INFO, "  TLS handshake threads : current %d / idle %d / max %d",
		g_thread_pool_get_num_threads(ctx->pool_tls_handshake),
		g_thread_pool_get_num_unused_threads(),
		g_thread_pool_get_max_threads(ctx->pool_tls_handshake) );
log_printf(DEBUG_LEVEL_INFO, "  TLS worker threads : current %d / idle %d / max %d",
		g_thread_pool_get_num_threads(ctx->pool_reader),
		g_thread_pool_get_num_unused_threads(),
		g_thread_pool_get_max_threads(ctx->pool_reader) );
}
Exemplo n.º 3
0
/**
 * entangle_pixbuf_loader_get_workers:
 * @loader: the pixbuf loader
 *
 * Get the number of worker threads associated with the loader
 *
 * Returns: the maximum number of worker threads
 */
int entangle_pixbuf_loader_get_workers(EntanglePixbufLoader *loader)
{
    g_return_val_if_fail(ENTANGLE_IS_PIXBUF_LOADER(loader), 0);

    EntanglePixbufLoaderPrivate *priv = loader->priv;

    return g_thread_pool_get_max_threads(priv->workers);
}
/**
 * mate_vfs_async_get_job_limit:
 * 
 * Get the current maximum allowable number of
 * worker threads for async operations.
 *
 * Return value: current maximum number of threads.
 */
int
mate_vfs_async_get_job_limit (void)
{
	return g_thread_pool_get_max_threads (thread_pool);
}