gthreadpool.h

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

Copyright © Nokia Corporation 2001-2008
Back to top