選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。
 
 
 
 
 
 

115 行
4.9 KiB

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