williamr@2: /* GLIB - Library of useful routines for C programming williamr@2: * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald williamr@2: * Portions copyright (c) 2006 Nokia Corporation. All rights reserved. williamr@2: * williamr@2: * This library is free software; you can redistribute it and/or williamr@2: * modify it under the terms of the GNU Lesser General Public williamr@2: * License as published by the Free Software Foundation; either williamr@2: * version 2 of the License, or (at your option) any later version. williamr@2: * williamr@2: * This library is distributed in the hope that it will be useful, williamr@2: * but WITHOUT ANY WARRANTY; without even the implied warranty of williamr@2: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU williamr@2: * Lesser General Public License for more details. williamr@2: * williamr@2: * You should have received a copy of the GNU Lesser General Public williamr@2: * License along with this library; if not, write to the williamr@2: * Free Software Foundation, Inc., 59 Temple Place - Suite 330, williamr@2: * Boston, MA 02111-1307, USA. williamr@2: */ williamr@2: williamr@2: /* williamr@2: * Modified by the GLib Team and others 1997-2000. See the AUTHORS williamr@2: * file for a list of people on the GLib Team. See the ChangeLog williamr@2: * files for a list of changes. These files are distributed with williamr@2: * GLib at ftp://ftp.gtk.org/pub/gtk/. williamr@2: */ williamr@2: williamr@2: #ifndef __G_THREADPOOL_H__ williamr@2: #define __G_THREADPOOL_H__ williamr@2: williamr@2: #include <_ansi.h> williamr@2: #include williamr@2: williamr@2: G_BEGIN_DECLS williamr@2: williamr@2: typedef struct _GThreadPool GThreadPool; williamr@2: williamr@2: /* Thread Pools williamr@2: */ williamr@2: williamr@2: /* The real GThreadPool is bigger, so you may only create a thread williamr@2: * pool with the constructor function */ williamr@2: struct _GThreadPool williamr@2: { williamr@2: GFunc func; williamr@2: gpointer user_data; williamr@2: gboolean exclusive; williamr@2: }; williamr@2: williamr@2: /* Get a thread pool with the function func, at most max_threads may williamr@2: * run at a time (max_threads == -1 means no limit), exclusive == TRUE williamr@2: * means, that the threads shouldn't be shared and that they will be williamr@2: * prestarted (otherwise they are started as needed) user_data is the williamr@2: * 2nd argument to the func */ williamr@2: IMPORT_C GThreadPool* g_thread_pool_new (GFunc func, williamr@2: gpointer user_data, williamr@2: gint max_threads, williamr@2: gboolean exclusive, williamr@2: GError **error); williamr@2: williamr@2: /* Push new data into the thread pool. This task is assigned to a thread later williamr@2: * (when the maximal number of threads is reached for that pool) or now williamr@2: * (otherwise). If necessary a new thread will be started. The function williamr@2: * returns immediatly */ williamr@2: IMPORT_C void g_thread_pool_push (GThreadPool *pool, williamr@2: gpointer data, williamr@2: GError **error); williamr@2: williamr@2: /* Set the number of threads, which can run concurrently for that pool, -1 williamr@2: * means no limit. 0 means has the effect, that the pool won't process williamr@2: * requests until the limit is set higher again */ williamr@2: IMPORT_C void g_thread_pool_set_max_threads (GThreadPool *pool, williamr@2: gint max_threads, williamr@2: GError **error); williamr@2: IMPORT_C gint g_thread_pool_get_max_threads (GThreadPool *pool); williamr@2: williamr@2: /* Get the number of threads assigned to that pool. This number doesn't williamr@2: * necessarily represent the number of working threads in that pool */ williamr@2: IMPORT_C guint g_thread_pool_get_num_threads (GThreadPool *pool); williamr@2: williamr@2: /* Get the number of unprocessed items in the pool */ williamr@2: IMPORT_C guint g_thread_pool_unprocessed (GThreadPool *pool); williamr@2: williamr@2: /* Free the pool, immediate means, that all unprocessed items in the queue williamr@2: * wont be processed, wait means, that the function doesn't return immediatly, williamr@2: * but after all threads in the pool are ready processing items. immediate williamr@2: * does however not mean, that threads are killed. */ williamr@2: IMPORT_C void g_thread_pool_free (GThreadPool *pool, williamr@2: gboolean immediate, williamr@2: gboolean wait); williamr@2: williamr@2: /* Set the maximal number of unused threads before threads will be stopped by williamr@2: * GLib, -1 means no limit */ williamr@2: IMPORT_C void g_thread_pool_set_max_unused_threads (gint max_threads); williamr@2: IMPORT_C gint g_thread_pool_get_max_unused_threads (void); williamr@2: IMPORT_C guint g_thread_pool_get_num_unused_threads (void); williamr@2: williamr@2: /* Stop all currently unused threads, but leave the limit untouched */ williamr@2: IMPORT_C void g_thread_pool_stop_unused_threads (void); williamr@2: williamr@2: /* Set sort function for priority threading */ williamr@2: IMPORT_C void g_thread_pool_set_sort_function (GThreadPool *pool, williamr@2: GCompareDataFunc func, williamr@2: gpointer user_data); williamr@2: williamr@2: /* Set maximum time a thread can be idle in the pool before it is stopped */ williamr@2: IMPORT_C void g_thread_pool_set_max_idle_time (guint interval); williamr@2: IMPORT_C guint g_thread_pool_get_max_idle_time (void); williamr@2: williamr@2: G_END_DECLS williamr@2: williamr@2: #endif /* __G_THREADPOOL_H__ */ williamr@2: