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