Initialize node->data->instance.private_size here rather than in
[glib.git] / glib / gthreadpool.h
blobed1e81ba350c34709bd493c388e5b500615fc676
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>
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 func;
44 gpointer user_data;
45 gboolean exclusive;
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,
54 gpointer user_data,
55 gint max_threads,
56 gboolean exclusive,
57 GError **error);
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,
64 gpointer data,
65 GError **error);
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,
71 gint max_threads,
72 GError **error);
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,
87 gboolean immediate,
88 gboolean wait);
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 G_END_DECLS
101 #endif /* __G_THREADPOOL_H__ */