gthread.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299
  1. /* GLIB - Library of useful routines for C programming
  2. * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
  3. *
  4. * SPDX-License-Identifier: LGPL-2.1-or-later
  5. *
  6. * This library is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Lesser General Public
  8. * License as published by the Free Software Foundation; either
  9. * version 2.1 of the License, or (at your option) any later version.
  10. *
  11. * This library is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public
  17. * License along with this library; if not, see <http://www.gnu.org/licenses/>.
  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. #ifndef __G_DEPRECATED_THREAD_H__
  26. #define __G_DEPRECATED_THREAD_H__
  27. #if !defined (__GLIB_H_INSIDE__) && !defined (GLIB_COMPILATION)
  28. #error "Only <glib.h> can be included directly."
  29. #endif
  30. #include <glib/gthread.h>
  31. G_BEGIN_DECLS
  32. G_GNUC_BEGIN_IGNORE_DEPRECATIONS
  33. typedef enum
  34. {
  35. G_THREAD_PRIORITY_LOW,
  36. G_THREAD_PRIORITY_NORMAL,
  37. G_THREAD_PRIORITY_HIGH,
  38. G_THREAD_PRIORITY_URGENT
  39. } GThreadPriority GLIB_DEPRECATED_TYPE_IN_2_32;
  40. struct _GThread
  41. {
  42. /*< private >*/
  43. GThreadFunc func;
  44. gpointer data;
  45. gboolean joinable;
  46. GThreadPriority priority;
  47. };
  48. typedef struct _GThreadFunctions GThreadFunctions GLIB_DEPRECATED_TYPE_IN_2_32;
  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. } GLIB_DEPRECATED_TYPE_IN_2_32;
  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 GLIB_DEPRECATED_MACRO_IN_2_32
  113. #ifndef G_OS_WIN32
  114. #define G_STATIC_MUTEX_INIT { NULL, PTHREAD_MUTEX_INITIALIZER } GLIB_DEPRECATED_MACRO_IN_2_32_FOR(g_mutex_init)
  115. #else
  116. #define G_STATIC_MUTEX_INIT { NULL } GLIB_DEPRECATED_MACRO_IN_2_32_FOR(g_mutex_init)
  117. #endif
  118. typedef struct
  119. {
  120. GMutex *mutex;
  121. #ifndef __GI_SCANNER__
  122. # ifndef G_OS_WIN32
  123. /* only for ABI compatibility reasons */
  124. pthread_mutex_t unused;
  125. # endif /* !G_OS_WIN32 */
  126. #endif /* !__GI_SCANNER__ */
  127. } GStaticMutex GLIB_DEPRECATED_TYPE_IN_2_32_FOR(GMutex);
  128. #define g_static_mutex_lock(mutex) \
  129. g_mutex_lock (g_static_mutex_get_mutex (mutex)) GLIB_DEPRECATED_MACRO_IN_2_32_FOR(g_mutex_lock)
  130. #define g_static_mutex_trylock(mutex) \
  131. g_mutex_trylock (g_static_mutex_get_mutex (mutex)) GLIB_DEPRECATED_MACRO_IN_2_32_FOR(g_mutex_trylock)
  132. #define g_static_mutex_unlock(mutex) \
  133. g_mutex_unlock (g_static_mutex_get_mutex (mutex)) GLIB_DEPRECATED_MACRO_IN_2_32_FOR(g_mutex_unlock)
  134. GLIB_DEPRECATED_IN_2_32_FOR(g_mutex_init)
  135. void g_static_mutex_init (GStaticMutex *mutex);
  136. GLIB_DEPRECATED_IN_2_32_FOR(g_mutex_clear)
  137. void g_static_mutex_free (GStaticMutex *mutex);
  138. GLIB_DEPRECATED_IN_2_32_FOR(GMutex)
  139. GMutex *g_static_mutex_get_mutex_impl (GStaticMutex *mutex);
  140. typedef struct _GStaticRecMutex GStaticRecMutex GLIB_DEPRECATED_TYPE_IN_2_32_FOR(GRecMutex);
  141. struct _GStaticRecMutex
  142. {
  143. /*< private >*/
  144. GStaticMutex mutex;
  145. guint depth;
  146. #ifndef __GI_SCANNER__
  147. /* ABI compat only */
  148. union {
  149. # ifdef G_OS_WIN32
  150. void *owner;
  151. # else
  152. pthread_t owner;
  153. # endif /* !G_OS_WIN32 */
  154. gdouble dummy;
  155. } unused;
  156. #endif /* !__GI_SCANNER__ */
  157. } GLIB_DEPRECATED_TYPE_IN_2_32_FOR(GRecMutex);
  158. #define G_STATIC_REC_MUTEX_INIT { G_STATIC_MUTEX_INIT, 0, { 0 } } GLIB_DEPRECATED_MACRO_IN_2_32_FOR(g_rec_mutex_init)
  159. GLIB_DEPRECATED_IN_2_32_FOR(g_rec_mutex_init)
  160. void g_static_rec_mutex_init (GStaticRecMutex *mutex);
  161. GLIB_DEPRECATED_IN_2_32_FOR(g_rec_mutex_lock)
  162. void g_static_rec_mutex_lock (GStaticRecMutex *mutex);
  163. GLIB_DEPRECATED_IN_2_32_FOR(g_rec_mutex_try_lock)
  164. gboolean g_static_rec_mutex_trylock (GStaticRecMutex *mutex);
  165. GLIB_DEPRECATED_IN_2_32_FOR(g_rec_mutex_unlock)
  166. void g_static_rec_mutex_unlock (GStaticRecMutex *mutex);
  167. GLIB_DEPRECATED_IN_2_32
  168. void g_static_rec_mutex_lock_full (GStaticRecMutex *mutex,
  169. guint depth);
  170. GLIB_DEPRECATED_IN_2_32
  171. guint g_static_rec_mutex_unlock_full (GStaticRecMutex *mutex);
  172. GLIB_DEPRECATED_IN_2_32_FOR(g_rec_mutex_free)
  173. void g_static_rec_mutex_free (GStaticRecMutex *mutex);
  174. typedef struct _GStaticRWLock GStaticRWLock GLIB_DEPRECATED_TYPE_IN_2_32_FOR(GRWLock);
  175. struct _GStaticRWLock
  176. {
  177. /*< private >*/
  178. GStaticMutex mutex;
  179. GCond *read_cond;
  180. GCond *write_cond;
  181. guint read_counter;
  182. gboolean have_writer;
  183. guint want_to_read;
  184. guint want_to_write;
  185. } GLIB_DEPRECATED_TYPE_IN_2_32_FOR(GRWLock);
  186. #define G_STATIC_RW_LOCK_INIT { G_STATIC_MUTEX_INIT, NULL, NULL, 0, FALSE, 0, 0 } GLIB_DEPRECATED_MACRO_IN_2_32_FOR(g_rw_lock_init)
  187. GLIB_DEPRECATED_IN_2_32_FOR(g_rw_lock_init)
  188. void g_static_rw_lock_init (GStaticRWLock *lock);
  189. GLIB_DEPRECATED_IN_2_32_FOR(g_rw_lock_reader_lock)
  190. void g_static_rw_lock_reader_lock (GStaticRWLock *lock);
  191. GLIB_DEPRECATED_IN_2_32_FOR(g_rw_lock_reader_trylock)
  192. gboolean g_static_rw_lock_reader_trylock (GStaticRWLock *lock);
  193. GLIB_DEPRECATED_IN_2_32_FOR(g_rw_lock_reader_unlock)
  194. void g_static_rw_lock_reader_unlock (GStaticRWLock *lock);
  195. GLIB_DEPRECATED_IN_2_32_FOR(g_rw_lock_writer_lock)
  196. void g_static_rw_lock_writer_lock (GStaticRWLock *lock);
  197. GLIB_DEPRECATED_IN_2_32_FOR(g_rw_lock_writer_trylock)
  198. gboolean g_static_rw_lock_writer_trylock (GStaticRWLock *lock);
  199. GLIB_DEPRECATED_IN_2_32_FOR(g_rw_lock_writer_unlock)
  200. void g_static_rw_lock_writer_unlock (GStaticRWLock *lock);
  201. GLIB_DEPRECATED_IN_2_32_FOR(g_rw_lock_free)
  202. void g_static_rw_lock_free (GStaticRWLock *lock);
  203. GLIB_DEPRECATED_IN_2_32
  204. GPrivate * g_private_new (GDestroyNotify notify);
  205. typedef struct _GStaticPrivate GStaticPrivate GLIB_DEPRECATED_TYPE_IN_2_32_FOR(GPrivate);
  206. struct _GStaticPrivate
  207. {
  208. /*< private >*/
  209. guint index;
  210. } GLIB_DEPRECATED_TYPE_IN_2_32_FOR(GPrivate);
  211. #define G_STATIC_PRIVATE_INIT { 0 } GLIB_DEPRECATED_MACRO_IN_2_32_FOR(G_PRIVATE_INIT)
  212. GLIB_DEPRECATED_IN_2_32
  213. void g_static_private_init (GStaticPrivate *private_key);
  214. GLIB_DEPRECATED_IN_2_32_FOR(g_private_get)
  215. gpointer g_static_private_get (GStaticPrivate *private_key);
  216. GLIB_DEPRECATED_IN_2_32_FOR(g_private_set)
  217. void g_static_private_set (GStaticPrivate *private_key,
  218. gpointer data,
  219. GDestroyNotify notify);
  220. GLIB_DEPRECATED_IN_2_32
  221. void g_static_private_free (GStaticPrivate *private_key);
  222. GLIB_DEPRECATED_IN_2_32
  223. gboolean g_once_init_enter_impl (volatile gsize *location);
  224. GLIB_DEPRECATED_IN_2_32
  225. void g_thread_init (gpointer vtable);
  226. GLIB_DEPRECATED_IN_2_32
  227. void g_thread_init_with_errorcheck_mutexes (gpointer vtable);
  228. GLIB_DEPRECATED_IN_2_32
  229. gboolean g_thread_get_initialized (void);
  230. GLIB_VAR gboolean g_threads_got_initialized;
  231. #define g_thread_supported() (1) GLIB_DEPRECATED_MACRO_IN_2_32
  232. GLIB_DEPRECATED_IN_2_32
  233. GMutex * g_mutex_new (void);
  234. GLIB_DEPRECATED_IN_2_32
  235. void g_mutex_free (GMutex *mutex);
  236. GLIB_DEPRECATED_IN_2_32
  237. GCond * g_cond_new (void);
  238. GLIB_DEPRECATED_IN_2_32
  239. void g_cond_free (GCond *cond);
  240. GLIB_DEPRECATED_IN_2_32
  241. gboolean g_cond_timed_wait (GCond *cond,
  242. GMutex *mutex,
  243. GTimeVal *abs_time);
  244. G_GNUC_END_IGNORE_DEPRECATIONS
  245. G_END_DECLS
  246. #endif /* __G_DEPRECATED_THREAD_H__ */