1 /* GLIB - Library of useful routines for C programming
2 * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
21 * Modified by the GLib Team and others 1997-2000. See the AUTHORS
22 * file for a list of people on the GLib Team. See the ChangeLog
23 * files for a list of changes. These files are distributed with
24 * GLib at ftp://ftp.gtk.org/pub/gtk/.
27 #ifndef __G_THREADPOOL_H__
28 #define __G_THREADPOOL_H__
30 #include <glib/gthread.h>
34 typedef struct _GThreadPool GThreadPool;
39 /* The real GThreadPool is bigger, so you may only create a thread
40 * pool with the constructor function */
48 /* Get a thread pool with the function func, at most max_threads may
49 * run at a time (max_threads == -1 means no limit), exclusive == TRUE
50 * means, that the threads shouldn't be shared and that they will be
51 * prestarted (otherwise they are started as needed) user_data is the
52 * 2nd argument to the func */
53 GThreadPool* g_thread_pool_new (GFunc func,
59 /* Push new data into the thread pool. This task is assigned to a thread later
60 * (when the maximal number of threads is reached for that pool) or now
61 * (otherwise). If necessary a new thread will be started. The function
62 * returns immediatly */
63 void g_thread_pool_push (GThreadPool *pool,
67 /* Set the number of threads, which can run concurrently for that pool, -1
68 * means no limit. 0 means has the effect, that the pool won't process
69 * requests until the limit is set higher again */
70 void g_thread_pool_set_max_threads (GThreadPool *pool,
73 gint g_thread_pool_get_max_threads (GThreadPool *pool);
75 /* Get the number of threads assigned to that pool. This number doesn't
76 * necessarily represent the number of working threads in that pool */
77 guint g_thread_pool_get_num_threads (GThreadPool *pool);
79 /* Get the number of unprocessed items in the pool */
80 guint g_thread_pool_unprocessed (GThreadPool *pool);
82 /* Free the pool, immediate means, that all unprocessed items in the queue
83 * wont be processed, wait means, that the function doesn't return immediatly,
84 * but after all threads in the pool are ready processing items. immediate
85 * does however not mean, that threads are killed. */
86 void g_thread_pool_free (GThreadPool *pool,
90 /* Set the maximal number of unused threads before threads will be stopped by
91 * GLib, -1 means no limit */
92 void g_thread_pool_set_max_unused_threads (gint max_threads);
93 gint g_thread_pool_get_max_unused_threads (void);
94 guint g_thread_pool_get_num_unused_threads (void);
96 /* Stop all currently unused threads, but leave the limit untouched */
97 void g_thread_pool_stop_unused_threads (void);
99 /* Set sort function for priority threading */
100 void g_thread_pool_set_sort_function (GThreadPool *pool,
101 GCompareDataFunc func,
104 /* Set maximum time a thread can be idle in the pool before it is stopped */
105 void g_thread_pool_set_max_idle_time (guint interval);
106 guint g_thread_pool_get_max_idle_time (void);
110 #endif /* __G_THREADPOOL_H__ */