1 /* GLIB - Library of useful routines for C programming 2 * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald 3 * 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. 8 * 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. 13 * 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. 18 */ 19 20 /* 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/. 25 */ 26 27 #if defined(G_DISABLE_SINGLE_INCLUDES) && !defined (__GLIB_H_INSIDE__) && !defined (GLIB_COMPILATION) 28 #error "Only <glib.h> can be included directly." 29 #endif 30 31 #ifndef __G_THREADPOOL_H__ 32 #define __G_THREADPOOL_H__ 33 34 #include <glib/gthread.h> 35 36 G_BEGIN_DECLS 37 38 typedef struct _GThreadPool GThreadPool; 39 40 /* Thread Pools 41 */ 42 43 /* The real GThreadPool is bigger, so you may only create a thread 44 * pool with the constructor function */ 45 struct _GThreadPool 46 { 47 GFunc func; 48 gpointer user_data; 49 gboolean exclusive; 50 }; 51 52 /* Get a thread pool with the function func, at most max_threads may 53 * run at a time (max_threads == -1 means no limit), exclusive == TRUE 54 * means, that the threads shouldn't be shared and that they will be 55 * prestarted (otherwise they are started as needed) user_data is the 56 * 2nd argument to the func */ 57 GThreadPool* g_thread_pool_new (GFunc func, 58 gpointer user_data, 59 gint max_threads, 60 gboolean exclusive, 61 GError **error); 62 63 /* Push new data into the thread pool. This task is assigned to a thread later 64 * (when the maximal number of threads is reached for that pool) or now 65 * (otherwise). If necessary a new thread will be started. The function 66 * returns immediatly */ 67 void g_thread_pool_push (GThreadPool *pool, 68 gpointer data, 69 GError **error); 70 71 /* Set the number of threads, which can run concurrently for that pool, -1 72 * means no limit. 0 means has the effect, that the pool won't process 73 * requests until the limit is set higher again */ 74 void g_thread_pool_set_max_threads (GThreadPool *pool, 75 gint max_threads, 76 GError **error); 77 gint g_thread_pool_get_max_threads (GThreadPool *pool); 78 79 /* Get the number of threads assigned to that pool. This number doesn't 80 * necessarily represent the number of working threads in that pool */ 81 guint g_thread_pool_get_num_threads (GThreadPool *pool); 82 83 /* Get the number of unprocessed items in the pool */ 84 guint g_thread_pool_unprocessed (GThreadPool *pool); 85 86 /* Free the pool, immediate means, that all unprocessed items in the queue 87 * wont be processed, wait means, that the function doesn't return immediatly, 88 * but after all threads in the pool are ready processing items. immediate 89 * does however not mean, that threads are killed. */ 90 void g_thread_pool_free (GThreadPool *pool, 91 gboolean immediate, 92 gboolean wait_); 93 94 /* Set the maximal number of unused threads before threads will be stopped by 95 * GLib, -1 means no limit */ 96 void g_thread_pool_set_max_unused_threads (gint max_threads); 97 gint g_thread_pool_get_max_unused_threads (void); 98 guint g_thread_pool_get_num_unused_threads (void); 99 100 /* Stop all currently unused threads, but leave the limit untouched */ 101 void g_thread_pool_stop_unused_threads (void); 102 103 /* Set sort function for priority threading */ 104 void g_thread_pool_set_sort_function (GThreadPool *pool, 105 GCompareDataFunc func, 106 gpointer user_data); 107 108 /* Set maximum time a thread can be idle in the pool before it is stopped */ 109 void g_thread_pool_set_max_idle_time (guint interval); 110 guint g_thread_pool_get_max_idle_time (void); 111 112 G_END_DECLS 113 114 #endif /* __G_THREADPOOL_H__ */ 115