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