gthread.h 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293
  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, see <http://www.gnu.org/licenses/>.
  16. */
  17. /*
  18. * Modified by the GLib Team and others 1997-2000. See the AUTHORS
  19. * file for a list of people on the GLib Team. See the ChangeLog
  20. * files for a list of changes. These files are distributed with
  21. * GLib at ftp://ftp.gtk.org/pub/gtk/.
  22. */
  23. #ifndef __G_DEPRECATED_THREAD_H__
  24. #define __G_DEPRECATED_THREAD_H__
  25. #if !defined (__GLIB_H_INSIDE__) && !defined (GLIB_COMPILATION)
  26. #error "Only <glib.h> can be included directly."
  27. #endif
  28. #include <glib/gthread.h>
  29. G_BEGIN_DECLS
  30. #ifndef G_DISABLE_DEPRECATED
  31. typedef enum
  32. {
  33. G_THREAD_PRIORITY_LOW,
  34. G_THREAD_PRIORITY_NORMAL,
  35. G_THREAD_PRIORITY_HIGH,
  36. G_THREAD_PRIORITY_URGENT
  37. } GThreadPriority;
  38. #endif
  39. struct _GThread
  40. {
  41. /*< private >*/
  42. GThreadFunc func;
  43. gpointer data;
  44. gboolean joinable;
  45. GThreadPriority priority;
  46. };
  47. #ifndef G_DISABLE_DEPRECATED
  48. typedef struct _GThreadFunctions GThreadFunctions;
  49. struct _GThreadFunctions
  50. {
  51. GMutex* (*mutex_new) (void);
  52. void (*mutex_lock) (GMutex *mutex);
  53. gboolean (*mutex_trylock) (GMutex *mutex);
  54. void (*mutex_unlock) (GMutex *mutex);
  55. void (*mutex_free) (GMutex *mutex);
  56. GCond* (*cond_new) (void);
  57. void (*cond_signal) (GCond *cond);
  58. void (*cond_broadcast) (GCond *cond);
  59. void (*cond_wait) (GCond *cond,
  60. GMutex *mutex);
  61. gboolean (*cond_timed_wait) (GCond *cond,
  62. GMutex *mutex,
  63. GTimeVal *end_time);
  64. void (*cond_free) (GCond *cond);
  65. GPrivate* (*private_new) (GDestroyNotify destructor);
  66. gpointer (*private_get) (GPrivate *private_key);
  67. void (*private_set) (GPrivate *private_key,
  68. gpointer data);
  69. void (*thread_create) (GThreadFunc func,
  70. gpointer data,
  71. gulong stack_size,
  72. gboolean joinable,
  73. gboolean bound,
  74. GThreadPriority priority,
  75. gpointer thread,
  76. GError **error);
  77. void (*thread_yield) (void);
  78. void (*thread_join) (gpointer thread);
  79. void (*thread_exit) (void);
  80. void (*thread_set_priority)(gpointer thread,
  81. GThreadPriority priority);
  82. void (*thread_self) (gpointer thread);
  83. gboolean (*thread_equal) (gpointer thread1,
  84. gpointer thread2);
  85. };
  86. GLIB_VAR GThreadFunctions g_thread_functions_for_glib_use;
  87. GLIB_VAR gboolean g_thread_use_default_impl;
  88. GLIB_VAR guint64 (*g_thread_gettime) (void);
  89. GLIB_DEPRECATED_IN_2_32_FOR(g_thread_new)
  90. GThread *g_thread_create (GThreadFunc func,
  91. gpointer data,
  92. gboolean joinable,
  93. GError **error);
  94. GLIB_DEPRECATED_IN_2_32_FOR(g_thread_new)
  95. GThread *g_thread_create_full (GThreadFunc func,
  96. gpointer data,
  97. gulong stack_size,
  98. gboolean joinable,
  99. gboolean bound,
  100. GThreadPriority priority,
  101. GError **error);
  102. GLIB_DEPRECATED_IN_2_32
  103. void g_thread_set_priority (GThread *thread,
  104. GThreadPriority priority);
  105. GLIB_DEPRECATED_IN_2_32
  106. void g_thread_foreach (GFunc thread_func,
  107. gpointer user_data);
  108. #ifndef G_OS_WIN32
  109. #include <sys/types.h>
  110. #include <pthread.h>
  111. #endif
  112. #define g_static_mutex_get_mutex g_static_mutex_get_mutex_impl
  113. #define G_STATIC_MUTEX_INIT { NULL }
  114. typedef struct
  115. {
  116. GMutex *mutex;
  117. #ifndef G_OS_WIN32
  118. /* only for ABI compatibility reasons */
  119. pthread_mutex_t unused;
  120. #endif
  121. } GStaticMutex;
  122. #define g_static_mutex_lock(mutex) \
  123. g_mutex_lock (g_static_mutex_get_mutex (mutex))
  124. #define g_static_mutex_trylock(mutex) \
  125. g_mutex_trylock (g_static_mutex_get_mutex (mutex))
  126. #define g_static_mutex_unlock(mutex) \
  127. g_mutex_unlock (g_static_mutex_get_mutex (mutex))
  128. GLIB_DEPRECATED_IN_2_32_FOR(g_mutex_init)
  129. void g_static_mutex_init (GStaticMutex *mutex);
  130. GLIB_DEPRECATED_IN_2_32_FOR(g_mutex_clear)
  131. void g_static_mutex_free (GStaticMutex *mutex);
  132. GLIB_DEPRECATED_IN_2_32_FOR(GMutex)
  133. GMutex *g_static_mutex_get_mutex_impl (GStaticMutex *mutex);
  134. typedef struct _GStaticRecMutex GStaticRecMutex;
  135. struct _GStaticRecMutex
  136. {
  137. /*< private >*/
  138. GStaticMutex mutex;
  139. guint depth;
  140. /* ABI compat only */
  141. union {
  142. #ifdef G_OS_WIN32
  143. void *owner;
  144. #else
  145. pthread_t owner;
  146. #endif
  147. gdouble dummy;
  148. } unused;
  149. };
  150. #define G_STATIC_REC_MUTEX_INIT { G_STATIC_MUTEX_INIT }
  151. GLIB_DEPRECATED_IN_2_32_FOR(g_rec_mutex_init)
  152. void g_static_rec_mutex_init (GStaticRecMutex *mutex);
  153. GLIB_DEPRECATED_IN_2_32_FOR(g_rec_mutex_lock)
  154. void g_static_rec_mutex_lock (GStaticRecMutex *mutex);
  155. GLIB_DEPRECATED_IN_2_32_FOR(g_rec_mutex_try_lock)
  156. gboolean g_static_rec_mutex_trylock (GStaticRecMutex *mutex);
  157. GLIB_DEPRECATED_IN_2_32_FOR(g_rec_mutex_unlock)
  158. void g_static_rec_mutex_unlock (GStaticRecMutex *mutex);
  159. GLIB_DEPRECATED_IN_2_32
  160. void g_static_rec_mutex_lock_full (GStaticRecMutex *mutex,
  161. guint depth);
  162. GLIB_DEPRECATED_IN_2_32
  163. guint g_static_rec_mutex_unlock_full (GStaticRecMutex *mutex);
  164. GLIB_DEPRECATED_IN_2_32_FOR(g_rec_mutex_free)
  165. void g_static_rec_mutex_free (GStaticRecMutex *mutex);
  166. typedef struct _GStaticRWLock GStaticRWLock;
  167. struct _GStaticRWLock
  168. {
  169. /*< private >*/
  170. GStaticMutex mutex;
  171. GCond *read_cond;
  172. GCond *write_cond;
  173. guint read_counter;
  174. gboolean have_writer;
  175. guint want_to_read;
  176. guint want_to_write;
  177. };
  178. #define G_STATIC_RW_LOCK_INIT { G_STATIC_MUTEX_INIT, NULL, NULL, 0, FALSE, 0, 0 }
  179. GLIB_DEPRECATED_IN_2_32_FOR(g_rw_lock_init)
  180. void g_static_rw_lock_init (GStaticRWLock *lock);
  181. GLIB_DEPRECATED_IN_2_32_FOR(g_rw_lock_reader_lock)
  182. void g_static_rw_lock_reader_lock (GStaticRWLock *lock);
  183. GLIB_DEPRECATED_IN_2_32_FOR(g_rw_lock_reader_trylock)
  184. gboolean g_static_rw_lock_reader_trylock (GStaticRWLock *lock);
  185. GLIB_DEPRECATED_IN_2_32_FOR(g_rw_lock_reader_unlock)
  186. void g_static_rw_lock_reader_unlock (GStaticRWLock *lock);
  187. GLIB_DEPRECATED_IN_2_32_FOR(g_rw_lock_writer_lock)
  188. void g_static_rw_lock_writer_lock (GStaticRWLock *lock);
  189. GLIB_DEPRECATED_IN_2_32_FOR(g_rw_lock_writer_trylock)
  190. gboolean g_static_rw_lock_writer_trylock (GStaticRWLock *lock);
  191. GLIB_DEPRECATED_IN_2_32_FOR(g_rw_lock_writer_unlock)
  192. void g_static_rw_lock_writer_unlock (GStaticRWLock *lock);
  193. GLIB_DEPRECATED_IN_2_32_FOR(g_rw_lock_free)
  194. void g_static_rw_lock_free (GStaticRWLock *lock);
  195. GLIB_DEPRECATED_IN_2_32
  196. GPrivate * g_private_new (GDestroyNotify notify);
  197. typedef struct _GStaticPrivate GStaticPrivate;
  198. struct _GStaticPrivate
  199. {
  200. /*< private >*/
  201. guint index;
  202. };
  203. #define G_STATIC_PRIVATE_INIT { 0 }
  204. GLIB_DEPRECATED_IN_2_32
  205. void g_static_private_init (GStaticPrivate *private_key);
  206. GLIB_DEPRECATED_IN_2_32_FOR(g_private_get)
  207. gpointer g_static_private_get (GStaticPrivate *private_key);
  208. GLIB_DEPRECATED_IN_2_32_FOR(g_private_set)
  209. void g_static_private_set (GStaticPrivate *private_key,
  210. gpointer data,
  211. GDestroyNotify notify);
  212. GLIB_DEPRECATED_IN_2_32
  213. void g_static_private_free (GStaticPrivate *private_key);
  214. GLIB_DEPRECATED_IN_2_32
  215. gboolean g_once_init_enter_impl (volatile gsize *location);
  216. GLIB_DEPRECATED_IN_2_32
  217. void g_thread_init (gpointer vtable);
  218. GLIB_DEPRECATED_IN_2_32
  219. void g_thread_init_with_errorcheck_mutexes (gpointer vtable);
  220. GLIB_DEPRECATED_IN_2_32
  221. gboolean g_thread_get_initialized (void);
  222. GLIB_VAR gboolean g_threads_got_initialized;
  223. #define g_thread_supported() (1)
  224. GLIB_DEPRECATED_IN_2_32
  225. GMutex * g_mutex_new (void);
  226. GLIB_DEPRECATED_IN_2_32
  227. void g_mutex_free (GMutex *mutex);
  228. GLIB_DEPRECATED_IN_2_32
  229. GCond * g_cond_new (void);
  230. GLIB_DEPRECATED_IN_2_32
  231. void g_cond_free (GCond *cond);
  232. GLIB_DEPRECATED_IN_2_32
  233. gboolean g_cond_timed_wait (GCond *cond,
  234. GMutex *mutex,
  235. GTimeVal *timeval);
  236. #endif
  237. G_END_DECLS
  238. #endif /* __G_DEPRECATED_THREAD_H__ */