GThreadPool: cosmetic cleanups

Mostly documentation and formatting trivial, but also add
boolean return types to GError taking functions.
This commit is contained in:
Matthias Clasen
2011-10-01 18:20:27 -04:00
parent 81e161edf2
commit b17b02da79
2 changed files with 428 additions and 398 deletions

View File

@@ -37,10 +37,7 @@
* SECTION:thread_pools * SECTION:thread_pools
* @title: Thread Pools * @title: Thread Pools
* @short_description: pools of threads to execute work concurrently * @short_description: pools of threads to execute work concurrently
* @see_also: <para> <variablelist> <varlistentry> * @see_also: #GThread
* <term>#GThread</term> <listitem><para>GLib thread
* system.</para></listitem> </varlistentry> </variablelist>
* </para>
* *
* Sometimes you wish to asynchronously fork out the execution of work * Sometimes you wish to asynchronously fork out the execution of work
* and continue working in your own thread. If that will happen often, * and continue working in your own thread. If that will happen often,
@@ -53,11 +50,11 @@
* advantage is, that the threads can be shared between the different * advantage is, that the threads can be shared between the different
* subsystems of your program, when they are using GLib. * subsystems of your program, when they are using GLib.
* *
* To create a new thread pool, you use g_thread_pool_new(). It is * To create a new thread pool, you use g_thread_pool_new().
* destroyed by g_thread_pool_free(). * It is destroyed by g_thread_pool_free().
* *
* If you want to execute a certain task within a thread pool, you call * If you want to execute a certain task within a thread pool,
* g_thread_pool_push(). * you call g_thread_pool_push().
* *
* To get the current number of running threads you call * To get the current number of running threads you call
* g_thread_pool_get_num_threads(). To get the number of still * g_thread_pool_get_num_threads(). To get the number of still
@@ -71,7 +68,7 @@
* controlled by g_thread_pool_get_max_unused_threads() and * controlled by g_thread_pool_get_max_unused_threads() and
* g_thread_pool_set_max_unused_threads(). All currently unused threads * g_thread_pool_set_max_unused_threads(). All currently unused threads
* can be stopped by calling g_thread_pool_stop_unused_threads(). * can be stopped by calling g_thread_pool_stop_unused_threads().
**/ */
#define DEBUG_MSG(x) #define DEBUG_MSG(x)
/* #define DEBUG_MSG(args) g_printerr args ; g_printerr ("\n"); */ /* #define DEBUG_MSG(args) g_printerr args ; g_printerr ("\n"); */
@@ -85,14 +82,14 @@ typedef struct _GRealThreadPool GRealThreadPool;
* @exclusive: are all threads exclusive to this pool * @exclusive: are all threads exclusive to this pool
* *
* The #GThreadPool struct represents a thread pool. It has three * The #GThreadPool struct represents a thread pool. It has three
* public read-only members, but the underlying struct is bigger, so * public read-only members, but the underlying struct is bigger,
* you must not copy this struct. * so you must not copy this struct.
**/ */
struct _GRealThreadPool struct _GRealThreadPool
{ {
GThreadPool pool; GThreadPool pool;
GAsyncQueue* queue; GAsyncQueue* queue;
GCond* cond; GCond *cond;
gint max_threads; gint max_threads;
gint num_threads; gint num_threads;
gboolean running; gboolean running;
@@ -104,7 +101,8 @@ struct _GRealThreadPool
/* The following is just an address to mark the wakeup order for a /* The following is just an address to mark the wakeup order for a
* thread, it could be any address (as long, as it isn't a valid * thread, it could be any address (as long, as it isn't a valid
* GThreadPool address) */ * GThreadPool address)
*/
static const gpointer wakeup_thread_marker = (gpointer) &g_thread_pool_new; static const gpointer wakeup_thread_marker = (gpointer) &g_thread_pool_new;
static gint wakeup_thread_serial = 0; static gint wakeup_thread_serial = 0;
@@ -119,7 +117,7 @@ static void g_thread_pool_queue_push_unlocked (GRealThreadPool *poo
gpointer data); gpointer data);
static void g_thread_pool_free_internal (GRealThreadPool *pool); static void g_thread_pool_free_internal (GRealThreadPool *pool);
static gpointer g_thread_pool_thread_proxy (gpointer data); static gpointer g_thread_pool_thread_proxy (gpointer data);
static void g_thread_pool_start_thread (GRealThreadPool *pool, static gboolean g_thread_pool_start_thread (GRealThreadPool *pool,
GError **error); GError **error);
static void g_thread_pool_wakeup_and_stop_all (GRealThreadPool *pool); static void g_thread_pool_wakeup_and_stop_all (GRealThreadPool *pool);
static GRealThreadPool* g_thread_pool_wait_for_new_pool (void); static GRealThreadPool* g_thread_pool_wait_for_new_pool (void);
@@ -201,7 +199,8 @@ g_thread_pool_wait_for_new_pool (void)
/* If a wakeup marker has been relayed, this thread /* If a wakeup marker has been relayed, this thread
* will get out of the way for 100 microseconds to * will get out of the way for 100 microseconds to
* avoid receiving this marker again. */ * avoid receiving this marker again.
*/
g_usleep (100); g_usleep (100);
} }
} }
@@ -296,8 +295,7 @@ g_thread_pool_thread_proxy (gpointer data)
pool = data; pool = data;
DEBUG_MSG (("thread %p started for pool %p.", DEBUG_MSG (("thread %p started for pool %p.", g_thread_self (), pool));
g_thread_self (), pool));
g_async_queue_lock (pool->queue); g_async_queue_lock (pool->queue);
@@ -310,8 +308,8 @@ g_thread_pool_thread_proxy (gpointer data)
{ {
if (pool->running || !pool->immediate) if (pool->running || !pool->immediate)
{ {
/* A task was received and the thread pool is active, so /* A task was received and the thread pool is active,
* execute the function. * so execute the function.
*/ */
g_async_queue_unlock (pool->queue); g_async_queue_unlock (pool->queue);
DEBUG_MSG (("thread %p in pool %p calling func.", DEBUG_MSG (("thread %p in pool %p calling func.",
@@ -322,9 +320,7 @@ g_thread_pool_thread_proxy (gpointer data)
} }
else else
{ {
/* No task was received, so this thread goes to the global /* No task was received, so this thread goes to the global pool. */
* pool.
*/
gboolean free_pool = FALSE; gboolean free_pool = FALSE;
DEBUG_MSG (("thread %p leaving pool %p for global pool.", DEBUG_MSG (("thread %p leaving pool %p for global pool.",
@@ -384,8 +380,8 @@ g_thread_pool_thread_proxy (gpointer data)
g_thread_self (), pool)); g_thread_self (), pool));
/* pool->num_threads++ is not done here, but in /* pool->num_threads++ is not done here, but in
* g_thread_pool_start_thread to make the new started thread * g_thread_pool_start_thread to make the new started
* known to the pool, before itself can do it. * thread known to the pool before itself can do it.
*/ */
} }
} }
@@ -393,7 +389,7 @@ g_thread_pool_thread_proxy (gpointer data)
return NULL; return NULL;
} }
static void static gboolean
g_thread_pool_start_thread (GRealThreadPool *pool, g_thread_pool_start_thread (GRealThreadPool *pool,
GError **error) GError **error)
{ {
@@ -401,7 +397,7 @@ g_thread_pool_start_thread (GRealThreadPool *pool,
if (pool->num_threads >= pool->max_threads && pool->max_threads != -1) if (pool->num_threads >= pool->max_threads && pool->max_threads != -1)
/* Enough threads are already running */ /* Enough threads are already running */
return; return TRUE;
g_async_queue_lock (unused_thread_queue); g_async_queue_lock (unused_thread_queue);
@@ -416,13 +412,12 @@ g_thread_pool_start_thread (GRealThreadPool *pool,
if (!success) if (!success)
{ {
GError *local_error = NULL; GError *local_error = NULL;
/* No thread was found, we have to start a new one */
g_thread_create (g_thread_pool_thread_proxy, pool, FALSE, &local_error);
if (local_error) /* No thread was found, we have to start a new one */
if (!g_thread_create (g_thread_pool_thread_proxy, pool, FALSE, &local_error))
{ {
g_propagate_error (error, local_error); g_propagate_error (error, local_error);
return; return FALSE;
} }
} }
@@ -430,6 +425,8 @@ g_thread_pool_start_thread (GRealThreadPool *pool,
* here and not there * here and not there
*/ */
pool->num_threads++; pool->num_threads++;
return TRUE;
} }
/** /**
@@ -437,10 +434,10 @@ g_thread_pool_start_thread (GRealThreadPool *pool,
* @func: a function to execute in the threads of the new thread pool * @func: a function to execute in the threads of the new thread pool
* @user_data: user data that is handed over to @func every time it * @user_data: user data that is handed over to @func every time it
* is called * is called
* @max_threads: the maximal number of threads to execute concurrently in * @max_threads: the maximal number of threads to execute concurrently
* the new thread pool, -1 means no limit * in the new thread pool, -1 means no limit
* @exclusive: should this thread pool be exclusive? * @exclusive: should this thread pool be exclusive?
* @error: return location for error * @error: return location for error, or %NULL
* *
* This function creates a new thread pool. * This function creates a new thread pool.
* *
@@ -448,26 +445,26 @@ g_thread_pool_start_thread (GRealThreadPool *pool,
* created or an unused one is reused. At most @max_threads threads * created or an unused one is reused. At most @max_threads threads
* are running concurrently for this thread pool. @max_threads = -1 * are running concurrently for this thread pool. @max_threads = -1
* allows unlimited threads to be created for this thread pool. The * allows unlimited threads to be created for this thread pool. The
* newly created or reused thread now executes the function @func with * newly created or reused thread now executes the function @func
* the two arguments. The first one is the parameter to * with the two arguments. The first one is the parameter to
* g_thread_pool_push() and the second one is @user_data. * g_thread_pool_push() and the second one is @user_data.
* *
* The parameter @exclusive determines, whether the thread pool owns * The parameter @exclusive determines whether the thread pool owns
* all threads exclusive or whether the threads are shared * all threads exclusive or shares them with other thread pools.
* globally. If @exclusive is %TRUE, @max_threads threads are started * If @exclusive is %TRUE, @max_threads threads are started
* immediately and they will run exclusively for this thread pool until * immediately and they will run exclusively for this thread pool
* it is destroyed by g_thread_pool_free(). If @exclusive is %FALSE, * until it is destroyed by g_thread_pool_free(). If @exclusive is
* threads are created, when needed and shared between all * %FALSE, threads are created when needed and shared between all
* non-exclusive thread pools. This implies that @max_threads may not * non-exclusive thread pools. This implies that @max_threads may
* be -1 for exclusive thread pools. * not be -1 for exclusive thread pools.
* *
* @error can be %NULL to ignore errors, or non-%NULL to report * @error can be %NULL to ignore errors, or non-%NULL to report
* errors. An error can only occur when @exclusive is set to %TRUE and * errors. An error can only occur when @exclusive is set to %TRUE
* not all @max_threads threads could be created. * and not all @max_threads threads could be created.
* *
* Return value: the new #GThreadPool * Return value: the new #GThreadPool
**/ */
GThreadPool* GThreadPool *
g_thread_pool_new (GFunc func, g_thread_pool_new (GFunc func,
gpointer user_data, gpointer user_data,
gint max_threads, gint max_threads,
@@ -507,8 +504,8 @@ g_thread_pool_new (GFunc func,
while (retval->num_threads < retval->max_threads) while (retval->num_threads < retval->max_threads)
{ {
GError *local_error = NULL; GError *local_error = NULL;
g_thread_pool_start_thread (retval, &local_error);
if (local_error) if (!g_thread_pool_start_thread (retval, &local_error))
{ {
g_propagate_error (error, local_error); g_propagate_error (error, local_error);
break; break;
@@ -525,7 +522,7 @@ g_thread_pool_new (GFunc func,
* g_thread_pool_push: * g_thread_pool_push:
* @pool: a #GThreadPool * @pool: a #GThreadPool
* @data: a new task for @pool * @data: a new task for @pool
* @error: return location for error * @error: return location for error, or %NULL
* *
* Inserts @data into the list of tasks to be executed by @pool. When * Inserts @data into the list of tasks to be executed by @pool. When
* the number of currently running threads is lower than the maximal * the number of currently running threads is lower than the maximal
@@ -536,46 +533,66 @@ g_thread_pool_new (GFunc func,
* *
* @error can be %NULL to ignore errors, or non-%NULL to report * @error can be %NULL to ignore errors, or non-%NULL to report
* errors. An error can only occur when a new thread couldn't be * errors. An error can only occur when a new thread couldn't be
* created. In that case @data is simply appended to the queue of work * created. In that case @data is simply appended to the queue of
* to do. * work to do.
**/ *
void * Before version 2.32, this function did not return a success status.
*
* Return value: %TRUE on success, %FALSE if an error occurred
*/
gboolean
g_thread_pool_push (GThreadPool *pool, g_thread_pool_push (GThreadPool *pool,
gpointer data, gpointer data,
GError **error) GError **error)
{ {
GRealThreadPool *real; GRealThreadPool *real;
gboolean result;
real = (GRealThreadPool*) pool; real = (GRealThreadPool*) pool;
g_return_if_fail (real); g_return_val_if_fail (real, FALSE);
g_return_if_fail (real->running); g_return_val_if_fail (real->running, FALSE);
result = TRUE;
g_async_queue_lock (real->queue); g_async_queue_lock (real->queue);
if (g_async_queue_length_unlocked (real->queue) >= 0) if (g_async_queue_length_unlocked (real->queue) >= 0)
{
/* No thread is waiting in the queue */ /* No thread is waiting in the queue */
g_thread_pool_start_thread (real, error); GError *local_error = NULL;
if (!g_thread_pool_start_thread (real, &local_error))
{
g_propagate_error (error, local_error);
result = FALSE;
}
}
g_thread_pool_queue_push_unlocked (real, data); g_thread_pool_queue_push_unlocked (real, data);
g_async_queue_unlock (real->queue); g_async_queue_unlock (real->queue);
return result;
} }
/** /**
* g_thread_pool_set_max_threads: * g_thread_pool_set_max_threads:
* @pool: a #GThreadPool * @pool: a #GThreadPool
* @max_threads: a new maximal number of threads for @pool * @max_threads: a new maximal number of threads for @pool,
* @error: return location for error * or -1 for unlimited
* @error: return location for error, or %NULL
* *
* Sets the maximal allowed number of threads for @pool. A value of -1 * Sets the maximal allowed number of threads for @pool.
* means, that the maximal number of threads is unlimited. * A value of -1 means that the maximal number of threads
* is unlimited. If @pool is an exclusive thread pool, setting
* the maximal number of threads to -1 is not allowed.
* *
* Setting @max_threads to 0 means stopping all work for @pool. It is * Setting @max_threads to 0 means stopping all work for @pool.
* effectively frozen until @max_threads is set to a non-zero value * It is effectively frozen until @max_threads is set to a non-zero
* again. * value again.
* *
* A thread is never terminated while calling @func, as supplied by * A thread is never terminated while calling @func, as supplied by
* g_thread_pool_new (). Instead the maximal number of threads only * g_thread_pool_new(). Instead the maximal number of threads only
* has effect for the allocation of new threads in g_thread_pool_push(). * has effect for the allocation of new threads in g_thread_pool_push().
* A new thread is allocated, whenever the number of currently * A new thread is allocated, whenever the number of currently
* running threads in @pool is smaller than the maximal number. * running threads in @pool is smaller than the maximal number.
@@ -583,21 +600,28 @@ g_thread_pool_push (GThreadPool *pool,
* @error can be %NULL to ignore errors, or non-%NULL to report * @error can be %NULL to ignore errors, or non-%NULL to report
* errors. An error can only occur when a new thread couldn't be * errors. An error can only occur when a new thread couldn't be
* created. * created.
**/ *
void * Before version 2.32, this function did not return a success status.
*
* Return value: %TRUE on success, %FALSE if an error occurred
*/
gboolean
g_thread_pool_set_max_threads (GThreadPool *pool, g_thread_pool_set_max_threads (GThreadPool *pool,
gint max_threads, gint max_threads,
GError **error) GError **error)
{ {
GRealThreadPool *real; GRealThreadPool *real;
gint to_start; gint to_start;
gboolean result;
real = (GRealThreadPool*) pool; real = (GRealThreadPool*) pool;
g_return_if_fail (real); g_return_val_if_fail (real, FALSE);
g_return_if_fail (real->running); g_return_val_if_fail (real->running, FALSE);
g_return_if_fail (!real->pool.exclusive || max_threads != -1); g_return_val_if_fail (!real->pool.exclusive || max_threads != -1, FALSE);
g_return_if_fail (max_threads >= -1); g_return_val_if_fail (max_threads >= -1, FALSE);
result = TRUE;
g_async_queue_lock (real->queue); g_async_queue_lock (real->queue);
@@ -612,15 +636,17 @@ g_thread_pool_set_max_threads (GThreadPool *pool,
{ {
GError *local_error = NULL; GError *local_error = NULL;
g_thread_pool_start_thread (real, &local_error); if (!g_thread_pool_start_thread (real, &local_error))
if (local_error)
{ {
g_propagate_error (error, local_error); g_propagate_error (error, local_error);
result = FALSE;
break; break;
} }
} }
g_async_queue_unlock (real->queue); g_async_queue_unlock (real->queue);
return result;
} }
/** /**
@@ -630,7 +656,7 @@ g_thread_pool_set_max_threads (GThreadPool *pool,
* Returns the maximal number of threads for @pool. * Returns the maximal number of threads for @pool.
* *
* Return value: the maximal number of threads * Return value: the maximal number of threads
**/ */
gint gint
g_thread_pool_get_max_threads (GThreadPool *pool) g_thread_pool_get_max_threads (GThreadPool *pool)
{ {
@@ -656,7 +682,7 @@ g_thread_pool_get_max_threads (GThreadPool *pool)
* Returns the number of threads currently running in @pool. * Returns the number of threads currently running in @pool.
* *
* Return value: the number of threads currently running * Return value: the number of threads currently running
**/ */
guint guint
g_thread_pool_get_num_threads (GThreadPool *pool) g_thread_pool_get_num_threads (GThreadPool *pool)
{ {
@@ -682,7 +708,7 @@ g_thread_pool_get_num_threads (GThreadPool *pool)
* Returns the number of tasks still unprocessed in @pool. * Returns the number of tasks still unprocessed in @pool.
* *
* Return value: the number of unprocessed tasks * Return value: the number of unprocessed tasks
**/ */
guint guint
g_thread_pool_unprocessed (GThreadPool *pool) g_thread_pool_unprocessed (GThreadPool *pool)
{ {
@@ -707,18 +733,19 @@ g_thread_pool_unprocessed (GThreadPool *pool)
* *
* Frees all resources allocated for @pool. * Frees all resources allocated for @pool.
* *
* If @immediate is %TRUE, no new task is processed for * If @immediate is %TRUE, no new task is processed for @pool.
* @pool. Otherwise @pool is not freed before the last task is * Otherwise @pool is not freed before the last task is processed.
* processed. Note however, that no thread of this pool is * Note however, that no thread of this pool is interrupted, while
* interrupted, while processing a task. Instead at least all still * processing a task. Instead at least all still running threads
* running threads can finish their tasks before the @pool is freed. * can finish their tasks before the @pool is freed.
* *
* If @wait_ is %TRUE, the functions does not return before all tasks * If @wait_ is %TRUE, the functions does not return before all
* to be processed (dependent on @immediate, whether all or only the * tasks to be processed (dependent on @immediate, whether all
* currently running) are ready. Otherwise the function returns immediately. * or only the currently running) are ready. Otherwise the function
* returns immediately.
* *
* After calling this function @pool must not be used anymore. * After calling this function @pool must not be used anymore.
**/ */
void void
g_thread_pool_free (GThreadPool *pool, g_thread_pool_free (GThreadPool *pool,
gboolean immediate, gboolean immediate,
@@ -790,7 +817,7 @@ g_thread_pool_free_internal (GRealThreadPool* pool)
} }
static void static void
g_thread_pool_wakeup_and_stop_all (GRealThreadPool* pool) g_thread_pool_wakeup_and_stop_all (GRealThreadPool *pool)
{ {
guint i; guint i;
@@ -808,10 +835,10 @@ g_thread_pool_wakeup_and_stop_all (GRealThreadPool* pool)
* g_thread_pool_set_max_unused_threads: * g_thread_pool_set_max_unused_threads:
* @max_threads: maximal number of unused threads * @max_threads: maximal number of unused threads
* *
* Sets the maximal number of unused threads to @max_threads. If * Sets the maximal number of unused threads to @max_threads.
* @max_threads is -1, no limit is imposed on the number of unused * If @max_threads is -1, no limit is imposed on the number
* threads. * of unused threads.
**/ */
void void
g_thread_pool_set_max_unused_threads (gint max_threads) g_thread_pool_set_max_unused_threads (gint max_threads)
{ {
@@ -847,7 +874,7 @@ g_thread_pool_set_max_unused_threads (gint max_threads)
* Returns the maximal allowed number of unused threads. * Returns the maximal allowed number of unused threads.
* *
* Return value: the maximal number of unused threads * Return value: the maximal number of unused threads
**/ */
gint gint
g_thread_pool_get_max_unused_threads (void) g_thread_pool_get_max_unused_threads (void)
{ {
@@ -860,7 +887,7 @@ g_thread_pool_get_max_unused_threads (void)
* Returns the number of currently unused threads. * Returns the number of currently unused threads.
* *
* Return value: the number of currently unused threads * Return value: the number of currently unused threads
**/ */
guint guint
g_thread_pool_get_num_unused_threads (void) g_thread_pool_get_num_unused_threads (void)
{ {
@@ -873,7 +900,7 @@ g_thread_pool_get_num_unused_threads (void)
* Stops all currently unused threads. This does not change the * Stops all currently unused threads. This does not change the
* maximal number of unused threads. This function can be used to * maximal number of unused threads. This function can be used to
* regularly stop all unused threads e.g. from g_timeout_add(). * regularly stop all unused threads e.g. from g_timeout_add().
**/ */
void void
g_thread_pool_stop_unused_threads (void) g_thread_pool_stop_unused_threads (void)
{ {
@@ -894,7 +921,7 @@ g_thread_pool_stop_unused_threads (void)
* a negative value if the first task should be processed before * a negative value if the first task should be processed before
* the second or a positive value if the second task should be * the second or a positive value if the second task should be
* processed first. * processed first.
* @user_data: user data passed to @func. * @user_data: user data passed to @func
* *
* Sets the function used to sort the list of tasks. This allows the * Sets the function used to sort the list of tasks. This allows the
* tasks to be processed by a priority determined by @func, and not * tasks to be processed by a priority determined by @func, and not
@@ -907,7 +934,7 @@ g_thread_pool_stop_unused_threads (void)
* created. * created.
* *
* Since: 2.10 * Since: 2.10
**/ */
void void
g_thread_pool_set_sort_function (GThreadPool *pool, g_thread_pool_set_sort_function (GThreadPool *pool,
GCompareDataFunc func, GCompareDataFunc func,
@@ -935,14 +962,14 @@ g_thread_pool_set_sort_function (GThreadPool *pool,
/** /**
* g_thread_pool_set_max_idle_time: * g_thread_pool_set_max_idle_time:
* @interval: the maximum @interval (1/1000ths of a second) a thread * @interval: the maximum @interval (in milliseconds)
* can be idle. * a thread can be idle
* *
* This function will set the maximum @interval that a thread waiting * This function will set the maximum @interval that a thread
* in the pool for new tasks can be idle for before being * waiting in the pool for new tasks can be idle for before
* stopped. This function is similar to calling * being stopped. This function is similar to calling
* g_thread_pool_stop_unused_threads() on a regular timeout, except, * g_thread_pool_stop_unused_threads() on a regular timeout,
* this is done on a per thread basis. * except this is done on a per thread basis.
* *
* By setting @interval to 0, idle threads will not be stopped. * By setting @interval to 0, idle threads will not be stopped.
* *
@@ -950,7 +977,7 @@ g_thread_pool_set_sort_function (GThreadPool *pool,
* @interval. * @interval.
* *
* Since: 2.10 * Since: 2.10
**/ */
void void
g_thread_pool_set_max_idle_time (guint interval) g_thread_pool_set_max_idle_time (guint interval)
{ {
@@ -978,17 +1005,19 @@ g_thread_pool_set_max_idle_time (guint interval)
/** /**
* g_thread_pool_get_max_idle_time: * g_thread_pool_get_max_idle_time:
* *
* This function will return the maximum @interval that a thread will * This function will return the maximum @interval that a
* wait in the thread pool for new tasks before being stopped. * thread will wait in the thread pool for new tasks before
* being stopped.
* *
* If this function returns 0, threads waiting in the thread pool for * If this function returns 0, threads waiting in the thread
* new work are not stopped. * pool for new work are not stopped.
* *
* Return value: the maximum @interval to wait for new tasks in the * Return value: the maximum @interval (milliseconds) to wait
* thread pool before stopping the thread (1/1000ths of a second). * for new tasks in the thread pool before stopping the
* thread
* *
* Since: 2.10 * Since: 2.10
**/ */
guint guint
g_thread_pool_get_max_idle_time (void) g_thread_pool_get_max_idle_time (void)
{ {

View File

@@ -47,30 +47,31 @@ struct _GThreadPool
gboolean exclusive; gboolean exclusive;
}; };
GThreadPool* g_thread_pool_new (GFunc func, GThreadPool * g_thread_pool_new (GFunc func,
gpointer user_data, gpointer user_data,
gint max_threads, gint max_threads,
gboolean exclusive, gboolean exclusive,
GError **error); GError **error);
void g_thread_pool_push (GThreadPool *pool, void g_thread_pool_free (GThreadPool *pool,
gboolean immediate,
gboolean wait_);
gboolean g_thread_pool_push (GThreadPool *pool,
gpointer data, gpointer data,
GError **error); GError **error);
void g_thread_pool_set_max_threads (GThreadPool *pool, guint g_thread_pool_unprocessed (GThreadPool *pool);
void g_thread_pool_set_sort_function (GThreadPool *pool,
GCompareDataFunc func,
gpointer user_data);
gboolean g_thread_pool_set_max_threads (GThreadPool *pool,
gint max_threads, gint max_threads,
GError **error); GError **error);
gint g_thread_pool_get_max_threads (GThreadPool *pool); gint g_thread_pool_get_max_threads (GThreadPool *pool);
guint g_thread_pool_get_num_threads (GThreadPool *pool); guint g_thread_pool_get_num_threads (GThreadPool *pool);
guint g_thread_pool_unprocessed (GThreadPool *pool);
void g_thread_pool_free (GThreadPool *pool,
gboolean immediate,
gboolean wait_);
void g_thread_pool_set_max_unused_threads (gint max_threads); void g_thread_pool_set_max_unused_threads (gint max_threads);
gint g_thread_pool_get_max_unused_threads (void); gint g_thread_pool_get_max_unused_threads (void);
guint g_thread_pool_get_num_unused_threads (void); guint g_thread_pool_get_num_unused_threads (void);
void g_thread_pool_stop_unused_threads (void); void g_thread_pool_stop_unused_threads (void);
void g_thread_pool_set_sort_function (GThreadPool *pool,
GCompareDataFunc func,
gpointer user_data);
void g_thread_pool_set_max_idle_time (guint interval); void g_thread_pool_set_max_idle_time (guint interval);
guint g_thread_pool_get_max_idle_time (void); guint g_thread_pool_get_max_idle_time (void);