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__
34 typedef struct _GThreadPool GThreadPool;
39 /* The real GThreadPool is bigger, so you may only create a thread
40 * pool with the constructor function */
46 GThreadPriority priority;
50 /* Get a thread pool with the function func, at most max_threads may
51 * run at a time (max_threads == -1 means no limit), stack_size, bound,
52 * priority like in g_thread_create, exclusive == TRUE means, that the threads
53 * shouldn't be shared and that they will be prestarted (otherwise they are
54 * started as needed) user_data is the 2nd argument to the func */
55 GThreadPool* g_thread_pool_new (GFunc func,
60 GThreadPriority priority,
64 /* Push new data into the thread pool. This task is assigned to a thread later
65 * (when the maximal number of threads is reached for that pool) or now
66 * (otherwise). If necessary a new thread will be started. The function
67 * returns immediatly */
68 void g_thread_pool_push (GThreadPool *pool,
72 /* Set the number of threads, which can run concurrently for that pool, -1
73 * means no limit. 0 means has the effect, that the pool won't process
74 * requests until the limit is set higher again */
75 void g_thread_pool_set_max_threads (GThreadPool *pool,
78 gint g_thread_pool_get_max_threads (GThreadPool *pool);
80 /* Get the number of threads assigned to that pool. This number doesn't
81 * necessarily represent the number of working threads in that pool */
82 guint g_thread_pool_get_num_threads (GThreadPool *pool);
84 /* Get the number of unprocessed items in the pool */
85 guint g_thread_pool_unprocessed (GThreadPool *pool);
87 /* Free the pool, immediate means, that all unprocessed items in the queue
88 * wont be processed, wait means, that the function doesn't return immediatly,
89 * but after all threads in the pool are ready processing items. immediate
90 * does however not mean, that threads are killed. */
91 void g_thread_pool_free (GThreadPool *pool,
95 /* Set the maximal number of unused threads before threads will be stopped by
96 * GLib, -1 means no limit */
97 void g_thread_pool_set_max_unused_threads (gint max_threads);
98 gint g_thread_pool_get_max_unused_threads (void);
99 guint g_thread_pool_get_num_unused_threads (void);
101 /* Stop all currently unused threads, but leave the limit untouched */
102 void g_thread_pool_stop_unused_threads (void);
106 #endif /* __G_THREADPOOL_H__ */