00001 /* GLIB - Library of useful routines for C programming 00002 * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald 00003 * 00004 * This library is free software; you can redistribute it and/or 00005 * modify it under the terms of the GNU Lesser General Public 00006 * License as published by the Free Software Foundation; either 00007 * version 2 of the License, or (at your option) any later version. 00008 * 00009 * This library is distributed in the hope that it will be useful, 00010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00012 * Lesser General Public License for more details. 00013 * 00014 * You should have received a copy of the GNU Lesser General Public 00015 * License along with this library; if not, write to the 00016 * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 00017 * Boston, MA 02111-1307, USA. 00018 */ 00019 00020 /* 00021 * Modified by the GLib Team and others 1997-2000. See the AUTHORS 00022 * file for a list of people on the GLib Team. See the ChangeLog 00023 * files for a list of changes. These files are distributed with 00024 * GLib at ftp://ftp.gtk.org/pub/gtk/. 00025 */ 00026 00027 #ifndef __G_THREADPOOL_H__ 00028 #define __G_THREADPOOL_H__ 00029 00030 #include <gthread.h> 00031 00032 G_BEGIN_DECLS 00033 00034 typedef struct _GThreadPool GThreadPool; 00035 00036 /* Thread Pools 00037 */ 00038 00039 /* The real GThreadPool is bigger, so you may only create a thread 00040 * pool with the constructor function */ 00041 struct _GThreadPool 00042 { 00043 GFunc thread_func; 00044 gulong stack_size; 00045 gboolean bound; 00046 GThreadPriority priority; 00047 gboolean exclusive; 00048 gpointer user_data; 00049 }; 00050 00051 /* Get a thread pool with the function thread_func, at most max_threads may 00052 * run at a time (max_threads == -1 means no limit), stack_size, bound, 00053 * priority like in g_thread_create, exclusive == TRUE means, that the threads 00054 * shouldn't be shared and that they will be prestarted (otherwise they are 00055 * started, as needed) user_data is the 2nd argument to the thread_func */ 00056 GThreadPool* g_thread_pool_new (GFunc thread_func, 00057 gint max_threads, 00058 gulong stack_size, 00059 gboolean bound, 00060 GThreadPriority priority, 00061 gboolean exclusive, 00062 gpointer user_data, 00063 GError **error); 00064 00065 /* Push new data into the thread pool. This task is assigned to a thread later 00066 * (when the maximal number of threads is reached for that pool) or now 00067 * (otherwise). If necessary a new thread will be started. The function 00068 * returns immediatly */ 00069 void g_thread_pool_push (GThreadPool *pool, 00070 gpointer data, 00071 GError **error); 00072 00073 /* Set the number of threads, which can run concurrently for that pool, -1 00074 * means no limit. 0 means has the effect, that the pool won't process 00075 * requests until the limit is set higher again */ 00076 void g_thread_pool_set_max_threads (GThreadPool *pool, 00077 gint max_threads, 00078 GError **error); 00079 gint g_thread_pool_get_max_threads (GThreadPool *pool); 00080 00081 /* Get the number of threads assigned to that pool. This number doesn't 00082 * necessarily represent the number of working threads in that pool */ 00083 guint g_thread_pool_get_num_threads (GThreadPool *pool); 00084 00085 /* Get the number of unprocessed items in the pool */ 00086 guint g_thread_pool_unprocessed (GThreadPool *pool); 00087 00088 /* Free the pool, immediate means, that all unprocessed items in the queue 00089 * wont be processed, wait means, that the function doesn't return immediatly, 00090 * but after all threads in the pool are ready processing items. immediate 00091 * does however not mean, that threads are killed. */ 00092 void g_thread_pool_free (GThreadPool *pool, 00093 gboolean immediate, 00094 gboolean wait); 00095 00096 /* Set the maximal number of unused threads before threads will be stopped by 00097 * GLib, -1 means no limit */ 00098 void g_thread_pool_set_max_unused_threads (gint max_threads); 00099 gint g_thread_pool_get_max_unused_threads (void); 00100 guint g_thread_pool_get_num_unused_threads (void); 00101 00102 /* Stop all currently unused threads, but leave the limit untouched */ 00103 void g_thread_pool_stop_unused_threads (void); 00104 00105 G_END_DECLS 00106 00107 #endif /* __G_THREADPOOL_H__ */ 00108