Remove pollfds from the context here, not when actually freeing the
[glib.git] / gthreadpool.h
blobd6fa87c8a984f062395309a2bb1202645a4cb681
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 <gthread.h>
32 G_BEGIN_DECLS
34 typedef struct _GThreadPool GThreadPool;
36 /* Thread Pools
39 /* The real GThreadPool is bigger, so you may only create a thread
40 * pool with the constructor function */
41 struct _GThreadPool
43 GFunc thread_func;
44 gulong stack_size;
45 gboolean bound;
46 GThreadPriority priority;
47 gboolean exclusive;
48 gpointer user_data;
51 /* Get a thread pool with the function thread_func, at most max_threads may
52 * run at a time (max_threads == -1 means no limit), stack_size, bound,
53 * priority like in g_thread_create, exclusive == TRUE means, that the threads
54 * shouldn't be shared and that they will be prestarted (otherwise they are
55 * started, as needed) user_data is the 2nd argument to the thread_func */
56 GThreadPool* g_thread_pool_new (GFunc thread_func,
57 gint max_threads,
58 gulong stack_size,
59 gboolean bound,
60 GThreadPriority priority,
61 gboolean exclusive,
62 gpointer user_data,
63 GError **error);
65 /* Push new data into the thread pool. This task is assigned to a thread later
66 * (when the maximal number of threads is reached for that pool) or now
67 * (otherwise). If necessary a new thread will be started. The function
68 * returns immediatly */
69 void g_thread_pool_push (GThreadPool *pool,
70 gpointer data,
71 GError **error);
73 /* Set the number of threads, which can run concurrently for that pool, -1
74 * means no limit. 0 means has the effect, that the pool won't process
75 * requests until the limit is set higher again */
76 void g_thread_pool_set_max_threads (GThreadPool *pool,
77 gint max_threads,
78 GError **error);
79 gint g_thread_pool_get_max_threads (GThreadPool *pool);
81 /* Get the number of threads assigned to that pool. This number doesn't
82 * necessarily represent the number of working threads in that pool */
83 guint g_thread_pool_get_num_threads (GThreadPool *pool);
85 /* Get the number of unprocessed items in the pool */
86 guint g_thread_pool_unprocessed (GThreadPool *pool);
88 /* Free the pool, immediate means, that all unprocessed items in the queue
89 * wont be processed, wait means, that the function doesn't return immediatly,
90 * but after all threads in the pool are ready processing items. immediate
91 * does however not mean, that threads are killed. */
92 void g_thread_pool_free (GThreadPool *pool,
93 gboolean immediate,
94 gboolean wait);
96 /* Set the maximal number of unused threads before threads will be stopped by
97 * GLib, -1 means no limit */
98 void g_thread_pool_set_max_unused_threads (gint max_threads);
99 gint g_thread_pool_get_max_unused_threads (void);
100 guint g_thread_pool_get_num_unused_threads (void);
102 /* Stop all currently unused threads, but leave the limit untouched */
103 void g_thread_pool_stop_unused_threads (void);
105 G_END_DECLS
107 #endif /* __G_THREADPOOL_H__ */