Sebastian Wilhelmi | b1d1558 | 2000-10-12 11:52:07 +0000 | [diff] [blame] | 1 | /* GLIB - Library of useful routines for C programming |
| 2 | * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald |
| 3 | * |
Sébastien Wilmet | f9faac7 | 2017-01-05 12:47:07 +0100 | [diff] [blame] | 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.1 of the License, or (at your option) any later version. |
Sebastian Wilhelmi | b1d1558 | 2000-10-12 11:52:07 +0000 | [diff] [blame] | 8 | * |
Ryan Lortie | 08a6d81 | 2011-10-04 20:31:33 -0400 | [diff] [blame] | 9 | * This library is distributed in the hope that it will be useful, but |
| 10 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
Sebastian Wilhelmi | b1d1558 | 2000-10-12 11:52:07 +0000 | [diff] [blame] | 12 | * Lesser General Public License for more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU Lesser General Public |
Daniel Mustieles | 078dbda | 2014-01-23 12:58:29 +0100 | [diff] [blame] | 15 | * License along with this library; if not, see <http://www.gnu.org/licenses/>. |
Sebastian Wilhelmi | b1d1558 | 2000-10-12 11:52:07 +0000 | [diff] [blame] | 16 | */ |
| 17 | |
| 18 | /* |
| 19 | * Modified by the GLib Team and others 1997-2000. See the AUTHORS |
| 20 | * file for a list of people on the GLib Team. See the ChangeLog |
| 21 | * files for a list of changes. These files are distributed with |
Michael Natterer | f4bb21a | 2008-03-14 19:30:38 +0000 | [diff] [blame] | 22 | * GLib at ftp://ftp.gtk.org/pub/gtk/. |
Sebastian Wilhelmi | b1d1558 | 2000-10-12 11:52:07 +0000 | [diff] [blame] | 23 | */ |
| 24 | |
Matthias Clasen | e1b99b2 | 2012-12-27 23:43:14 -0500 | [diff] [blame] | 25 | #ifndef __G_THREAD_H__ |
| 26 | #define __G_THREAD_H__ |
| 27 | |
Matthias Clasen | 7455dd3 | 2011-10-12 00:24:46 -0400 | [diff] [blame] | 28 | #if !defined (__GLIB_H_INSIDE__) && !defined (GLIB_COMPILATION) |
Michael Natterer | f4bb21a | 2008-03-14 19:30:38 +0000 | [diff] [blame] | 29 | #error "Only <glib.h> can be included directly." |
| 30 | #endif |
| 31 | |
Ryan Lortie | 08a6d81 | 2011-10-04 20:31:33 -0400 | [diff] [blame] | 32 | #include <glib/gatomic.h> |
Owen Taylor | 2fd6b00 | 2001-06-26 16:01:21 +0000 | [diff] [blame] | 33 | #include <glib/gerror.h> |
Chun-wei Fan | 433fc94 | 2015-02-09 15:42:01 +0800 | [diff] [blame] | 34 | #include <glib/gutils.h> |
Sebastian Wilhelmi | b1d1558 | 2000-10-12 11:52:07 +0000 | [diff] [blame] | 35 | |
| 36 | G_BEGIN_DECLS |
| 37 | |
Sebastian Wilhelmi | 41e2001 | 2001-02-13 15:57:44 +0000 | [diff] [blame] | 38 | #define G_THREAD_ERROR g_thread_error_quark () |
Ryan Lortie | 0156092 | 2012-12-06 14:04:59 -0500 | [diff] [blame] | 39 | GLIB_AVAILABLE_IN_ALL |
Ryan Lortie | 08a6d81 | 2011-10-04 20:31:33 -0400 | [diff] [blame] | 40 | GQuark g_thread_error_quark (void); |
Sebastian Wilhelmi | b1d1558 | 2000-10-12 11:52:07 +0000 | [diff] [blame] | 41 | |
| 42 | typedef enum |
| 43 | { |
| 44 | G_THREAD_ERROR_AGAIN /* Resource temporarily unavailable */ |
| 45 | } GThreadError; |
| 46 | |
Sebastian Wilhelmi | a8c9dad | 2001-05-09 12:51:21 +0000 | [diff] [blame] | 47 | typedef gpointer (*GThreadFunc) (gpointer data); |
Sebastian Wilhelmi | b1d1558 | 2000-10-12 11:52:07 +0000 | [diff] [blame] | 48 | |
Sebastian Wilhelmi | b1d1558 | 2000-10-12 11:52:07 +0000 | [diff] [blame] | 49 | typedef struct _GThread GThread; |
Sebastian Wilhelmi | b1d1558 | 2000-10-12 11:52:07 +0000 | [diff] [blame] | 50 | |
Ryan Lortie | c5634df | 2011-10-02 20:59:15 -0400 | [diff] [blame] | 51 | typedef union _GMutex GMutex; |
Ryan Lortie | ad187e3 | 2011-09-21 14:36:53 -0400 | [diff] [blame] | 52 | typedef struct _GRecMutex GRecMutex; |
Ryan Lortie | 3d41027 | 2011-09-21 10:19:36 -0400 | [diff] [blame] | 53 | typedef struct _GRWLock GRWLock; |
Sebastian Wilhelmi | b1d1558 | 2000-10-12 11:52:07 +0000 | [diff] [blame] | 54 | typedef struct _GCond GCond; |
| 55 | typedef struct _GPrivate GPrivate; |
Ryan Lortie | 08a6d81 | 2011-10-04 20:31:33 -0400 | [diff] [blame] | 56 | typedef struct _GOnce GOnce; |
Sebastian Wilhelmi | b1d1558 | 2000-10-12 11:52:07 +0000 | [diff] [blame] | 57 | |
Ryan Lortie | c5634df | 2011-10-02 20:59:15 -0400 | [diff] [blame] | 58 | union _GMutex |
Ryan Lortie | 80730bc | 2011-09-16 18:05:23 -0400 | [diff] [blame] | 59 | { |
Ryan Lortie | c5634df | 2011-10-02 20:59:15 -0400 | [diff] [blame] | 60 | /*< private >*/ |
| 61 | gpointer p; |
| 62 | guint i[2]; |
Ryan Lortie | 3d41027 | 2011-09-21 10:19:36 -0400 | [diff] [blame] | 63 | }; |
| 64 | |
Ryan Lortie | 3d41027 | 2011-09-21 10:19:36 -0400 | [diff] [blame] | 65 | struct _GRWLock |
| 66 | { |
Ryan Lortie | c5634df | 2011-10-02 20:59:15 -0400 | [diff] [blame] | 67 | /*< private >*/ |
| 68 | gpointer p; |
| 69 | guint i[2]; |
Ryan Lortie | 80730bc | 2011-09-16 18:05:23 -0400 | [diff] [blame] | 70 | }; |
| 71 | |
Ryan Lortie | 80730bc | 2011-09-16 18:05:23 -0400 | [diff] [blame] | 72 | struct _GCond |
| 73 | { |
Ryan Lortie | c5634df | 2011-10-02 20:59:15 -0400 | [diff] [blame] | 74 | /*< private >*/ |
| 75 | gpointer p; |
| 76 | guint i[2]; |
Ryan Lortie | 80730bc | 2011-09-16 18:05:23 -0400 | [diff] [blame] | 77 | }; |
Ryan Lortie | 80730bc | 2011-09-16 18:05:23 -0400 | [diff] [blame] | 78 | |
Ryan Lortie | ad187e3 | 2011-09-21 14:36:53 -0400 | [diff] [blame] | 79 | struct _GRecMutex |
| 80 | { |
Ryan Lortie | c5634df | 2011-10-02 20:59:15 -0400 | [diff] [blame] | 81 | /*< private >*/ |
| 82 | gpointer p; |
| 83 | guint i[2]; |
Ryan Lortie | ad187e3 | 2011-09-21 14:36:53 -0400 | [diff] [blame] | 84 | }; |
| 85 | |
Ryan Lortie | 8e43470 | 2011-09-30 14:22:04 -0400 | [diff] [blame] | 86 | #define G_PRIVATE_INIT(notify) { NULL, (notify), { NULL, NULL } } |
| 87 | struct _GPrivate |
| 88 | { |
Ryan Lortie | 083812f | 2011-10-06 12:19:58 -0400 | [diff] [blame] | 89 | /*< private >*/ |
Ryan Lortie | 8e43470 | 2011-09-30 14:22:04 -0400 | [diff] [blame] | 90 | gpointer p; |
| 91 | GDestroyNotify notify; |
| 92 | gpointer future[2]; |
| 93 | }; |
| 94 | |
Matthias Clasen | 876f907 | 2003-07-08 23:43:48 +0000 | [diff] [blame] | 95 | typedef enum |
| 96 | { |
| 97 | G_ONCE_STATUS_NOTCALLED, |
| 98 | G_ONCE_STATUS_PROGRESS, |
Matthias Clasen | 81e395b | 2011-09-25 01:32:41 -0400 | [diff] [blame] | 99 | G_ONCE_STATUS_READY |
Matthias Clasen | 876f907 | 2003-07-08 23:43:48 +0000 | [diff] [blame] | 100 | } GOnceStatus; |
| 101 | |
Ryan Lortie | 08a6d81 | 2011-10-04 20:31:33 -0400 | [diff] [blame] | 102 | #define G_ONCE_INIT { G_ONCE_STATUS_NOTCALLED, NULL } |
Matthias Clasen | 876f907 | 2003-07-08 23:43:48 +0000 | [diff] [blame] | 103 | struct _GOnce |
| 104 | { |
| 105 | volatile GOnceStatus status; |
| 106 | volatile gpointer retval; |
| 107 | }; |
| 108 | |
Ryan Lortie | 08a6d81 | 2011-10-04 20:31:33 -0400 | [diff] [blame] | 109 | #define G_LOCK_NAME(name) g__ ## name ## _lock |
Dan Winship | 5bc7729 | 2011-08-31 14:01:45 -0400 | [diff] [blame] | 110 | #define G_LOCK_DEFINE_STATIC(name) static G_LOCK_DEFINE (name) |
Ryan Lortie | 2a677d1 | 2011-10-02 20:51:38 -0400 | [diff] [blame] | 111 | #define G_LOCK_DEFINE(name) GMutex G_LOCK_NAME (name) |
Ryan Lortie | cf26a6f | 2011-09-17 18:33:25 -0400 | [diff] [blame] | 112 | #define G_LOCK_EXTERN(name) extern GMutex G_LOCK_NAME (name) |
Sebastian Wilhelmi | b1d1558 | 2000-10-12 11:52:07 +0000 | [diff] [blame] | 113 | |
Dan Winship | 5bc7729 | 2011-08-31 14:01:45 -0400 | [diff] [blame] | 114 | #ifdef G_DEBUG_LOCKS |
| 115 | # define G_LOCK(name) G_STMT_START{ \ |
| 116 | g_log (G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, \ |
| 117 | "file %s: line %d (%s): locking: %s ", \ |
| 118 | __FILE__, __LINE__, G_STRFUNC, \ |
| 119 | #name); \ |
Ryan Lortie | cf26a6f | 2011-09-17 18:33:25 -0400 | [diff] [blame] | 120 | g_mutex_lock (&G_LOCK_NAME (name)); \ |
Dan Winship | 5bc7729 | 2011-08-31 14:01:45 -0400 | [diff] [blame] | 121 | }G_STMT_END |
| 122 | # define G_UNLOCK(name) G_STMT_START{ \ |
| 123 | g_log (G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, \ |
| 124 | "file %s: line %d (%s): unlocking: %s ", \ |
| 125 | __FILE__, __LINE__, G_STRFUNC, \ |
| 126 | #name); \ |
Ryan Lortie | cf26a6f | 2011-09-17 18:33:25 -0400 | [diff] [blame] | 127 | g_mutex_unlock (&G_LOCK_NAME (name)); \ |
Dan Winship | 5bc7729 | 2011-08-31 14:01:45 -0400 | [diff] [blame] | 128 | }G_STMT_END |
| 129 | # define G_TRYLOCK(name) \ |
| 130 | (g_log (G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, \ |
| 131 | "file %s: line %d (%s): try locking: %s ", \ |
| 132 | __FILE__, __LINE__, G_STRFUNC, \ |
Ryan Lortie | cf26a6f | 2011-09-17 18:33:25 -0400 | [diff] [blame] | 133 | #name), g_mutex_trylock (&G_LOCK_NAME (name))) |
Dan Winship | 5bc7729 | 2011-08-31 14:01:45 -0400 | [diff] [blame] | 134 | #else /* !G_DEBUG_LOCKS */ |
Ryan Lortie | cf26a6f | 2011-09-17 18:33:25 -0400 | [diff] [blame] | 135 | # define G_LOCK(name) g_mutex_lock (&G_LOCK_NAME (name)) |
| 136 | # define G_UNLOCK(name) g_mutex_unlock (&G_LOCK_NAME (name)) |
| 137 | # define G_TRYLOCK(name) g_mutex_trylock (&G_LOCK_NAME (name)) |
Dan Winship | 5bc7729 | 2011-08-31 14:01:45 -0400 | [diff] [blame] | 138 | #endif /* !G_DEBUG_LOCKS */ |
Sebastian Wilhelmi | b1d1558 | 2000-10-12 11:52:07 +0000 | [diff] [blame] | 139 | |
Will Thompson | 5ff99924 | 2012-11-14 14:59:42 +0000 | [diff] [blame] | 140 | GLIB_AVAILABLE_IN_2_32 |
Ryan Lortie | b0e73ca | 2011-10-13 00:29:04 -0400 | [diff] [blame] | 141 | GThread * g_thread_ref (GThread *thread); |
Will Thompson | 5ff99924 | 2012-11-14 14:59:42 +0000 | [diff] [blame] | 142 | GLIB_AVAILABLE_IN_2_32 |
Ryan Lortie | b0e73ca | 2011-10-13 00:29:04 -0400 | [diff] [blame] | 143 | void g_thread_unref (GThread *thread); |
Will Thompson | 5ff99924 | 2012-11-14 14:59:42 +0000 | [diff] [blame] | 144 | GLIB_AVAILABLE_IN_2_32 |
Ryan Lortie | 08a6d81 | 2011-10-04 20:31:33 -0400 | [diff] [blame] | 145 | GThread * g_thread_new (const gchar *name, |
| 146 | GThreadFunc func, |
Ryan Lortie | 430c563 | 2011-10-13 01:00:57 -0400 | [diff] [blame] | 147 | gpointer data); |
Will Thompson | 5ff99924 | 2012-11-14 14:59:42 +0000 | [diff] [blame] | 148 | GLIB_AVAILABLE_IN_2_32 |
Ryan Lortie | e75e9c3 | 2011-10-15 09:48:10 -0400 | [diff] [blame] | 149 | GThread * g_thread_try_new (const gchar *name, |
Ryan Lortie | 430c563 | 2011-10-13 01:00:57 -0400 | [diff] [blame] | 150 | GThreadFunc func, |
Ryan Lortie | 08a6d81 | 2011-10-04 20:31:33 -0400 | [diff] [blame] | 151 | gpointer data, |
Ryan Lortie | 08a6d81 | 2011-10-04 20:31:33 -0400 | [diff] [blame] | 152 | GError **error); |
Ryan Lortie | 0156092 | 2012-12-06 14:04:59 -0500 | [diff] [blame] | 153 | GLIB_AVAILABLE_IN_ALL |
Ryan Lortie | 08a6d81 | 2011-10-04 20:31:33 -0400 | [diff] [blame] | 154 | GThread * g_thread_self (void); |
Ryan Lortie | 0156092 | 2012-12-06 14:04:59 -0500 | [diff] [blame] | 155 | GLIB_AVAILABLE_IN_ALL |
Ryan Lortie | 08a6d81 | 2011-10-04 20:31:33 -0400 | [diff] [blame] | 156 | void g_thread_exit (gpointer retval); |
Ryan Lortie | 0156092 | 2012-12-06 14:04:59 -0500 | [diff] [blame] | 157 | GLIB_AVAILABLE_IN_ALL |
Ryan Lortie | 08a6d81 | 2011-10-04 20:31:33 -0400 | [diff] [blame] | 158 | gpointer g_thread_join (GThread *thread); |
Ryan Lortie | 0156092 | 2012-12-06 14:04:59 -0500 | [diff] [blame] | 159 | GLIB_AVAILABLE_IN_ALL |
Ryan Lortie | 08a6d81 | 2011-10-04 20:31:33 -0400 | [diff] [blame] | 160 | void g_thread_yield (void); |
Ryan Lortie | 80730bc | 2011-09-16 18:05:23 -0400 | [diff] [blame] | 161 | |
Ryan Lortie | 80730bc | 2011-09-16 18:05:23 -0400 | [diff] [blame] | 162 | |
Will Thompson | 5ff99924 | 2012-11-14 14:59:42 +0000 | [diff] [blame] | 163 | GLIB_AVAILABLE_IN_2_32 |
Ryan Lortie | 08a6d81 | 2011-10-04 20:31:33 -0400 | [diff] [blame] | 164 | void g_mutex_init (GMutex *mutex); |
Will Thompson | 5ff99924 | 2012-11-14 14:59:42 +0000 | [diff] [blame] | 165 | GLIB_AVAILABLE_IN_2_32 |
Ryan Lortie | 08a6d81 | 2011-10-04 20:31:33 -0400 | [diff] [blame] | 166 | void g_mutex_clear (GMutex *mutex); |
Ryan Lortie | 0156092 | 2012-12-06 14:04:59 -0500 | [diff] [blame] | 167 | GLIB_AVAILABLE_IN_ALL |
Ryan Lortie | 08a6d81 | 2011-10-04 20:31:33 -0400 | [diff] [blame] | 168 | void g_mutex_lock (GMutex *mutex); |
Ryan Lortie | 0156092 | 2012-12-06 14:04:59 -0500 | [diff] [blame] | 169 | GLIB_AVAILABLE_IN_ALL |
Ryan Lortie | 08a6d81 | 2011-10-04 20:31:33 -0400 | [diff] [blame] | 170 | gboolean g_mutex_trylock (GMutex *mutex); |
Ryan Lortie | 0156092 | 2012-12-06 14:04:59 -0500 | [diff] [blame] | 171 | GLIB_AVAILABLE_IN_ALL |
Ryan Lortie | 08a6d81 | 2011-10-04 20:31:33 -0400 | [diff] [blame] | 172 | void g_mutex_unlock (GMutex *mutex); |
Ryan Lortie | 80730bc | 2011-09-16 18:05:23 -0400 | [diff] [blame] | 173 | |
Will Thompson | 5ff99924 | 2012-11-14 14:59:42 +0000 | [diff] [blame] | 174 | GLIB_AVAILABLE_IN_2_32 |
Ryan Lortie | 08a6d81 | 2011-10-04 20:31:33 -0400 | [diff] [blame] | 175 | void g_rw_lock_init (GRWLock *rw_lock); |
Will Thompson | 5ff99924 | 2012-11-14 14:59:42 +0000 | [diff] [blame] | 176 | GLIB_AVAILABLE_IN_2_32 |
Ryan Lortie | 08a6d81 | 2011-10-04 20:31:33 -0400 | [diff] [blame] | 177 | void g_rw_lock_clear (GRWLock *rw_lock); |
Will Thompson | 5ff99924 | 2012-11-14 14:59:42 +0000 | [diff] [blame] | 178 | GLIB_AVAILABLE_IN_2_32 |
Ryan Lortie | 08a6d81 | 2011-10-04 20:31:33 -0400 | [diff] [blame] | 179 | void g_rw_lock_writer_lock (GRWLock *rw_lock); |
Will Thompson | 5ff99924 | 2012-11-14 14:59:42 +0000 | [diff] [blame] | 180 | GLIB_AVAILABLE_IN_2_32 |
Ryan Lortie | 08a6d81 | 2011-10-04 20:31:33 -0400 | [diff] [blame] | 181 | gboolean g_rw_lock_writer_trylock (GRWLock *rw_lock); |
Will Thompson | 5ff99924 | 2012-11-14 14:59:42 +0000 | [diff] [blame] | 182 | GLIB_AVAILABLE_IN_2_32 |
Ryan Lortie | 08a6d81 | 2011-10-04 20:31:33 -0400 | [diff] [blame] | 183 | void g_rw_lock_writer_unlock (GRWLock *rw_lock); |
Will Thompson | 5ff99924 | 2012-11-14 14:59:42 +0000 | [diff] [blame] | 184 | GLIB_AVAILABLE_IN_2_32 |
Ryan Lortie | 08a6d81 | 2011-10-04 20:31:33 -0400 | [diff] [blame] | 185 | void g_rw_lock_reader_lock (GRWLock *rw_lock); |
Will Thompson | 5ff99924 | 2012-11-14 14:59:42 +0000 | [diff] [blame] | 186 | GLIB_AVAILABLE_IN_2_32 |
Ryan Lortie | 08a6d81 | 2011-10-04 20:31:33 -0400 | [diff] [blame] | 187 | gboolean g_rw_lock_reader_trylock (GRWLock *rw_lock); |
Will Thompson | 5ff99924 | 2012-11-14 14:59:42 +0000 | [diff] [blame] | 188 | GLIB_AVAILABLE_IN_2_32 |
Ryan Lortie | 08a6d81 | 2011-10-04 20:31:33 -0400 | [diff] [blame] | 189 | void g_rw_lock_reader_unlock (GRWLock *rw_lock); |
Ryan Lortie | 3d41027 | 2011-09-21 10:19:36 -0400 | [diff] [blame] | 190 | |
Will Thompson | 5ff99924 | 2012-11-14 14:59:42 +0000 | [diff] [blame] | 191 | GLIB_AVAILABLE_IN_2_32 |
Ryan Lortie | 08a6d81 | 2011-10-04 20:31:33 -0400 | [diff] [blame] | 192 | void g_rec_mutex_init (GRecMutex *rec_mutex); |
Will Thompson | 5ff99924 | 2012-11-14 14:59:42 +0000 | [diff] [blame] | 193 | GLIB_AVAILABLE_IN_2_32 |
Ryan Lortie | 08a6d81 | 2011-10-04 20:31:33 -0400 | [diff] [blame] | 194 | void g_rec_mutex_clear (GRecMutex *rec_mutex); |
Will Thompson | 5ff99924 | 2012-11-14 14:59:42 +0000 | [diff] [blame] | 195 | GLIB_AVAILABLE_IN_2_32 |
Ryan Lortie | 08a6d81 | 2011-10-04 20:31:33 -0400 | [diff] [blame] | 196 | void g_rec_mutex_lock (GRecMutex *rec_mutex); |
Will Thompson | 5ff99924 | 2012-11-14 14:59:42 +0000 | [diff] [blame] | 197 | GLIB_AVAILABLE_IN_2_32 |
Ryan Lortie | 08a6d81 | 2011-10-04 20:31:33 -0400 | [diff] [blame] | 198 | gboolean g_rec_mutex_trylock (GRecMutex *rec_mutex); |
Will Thompson | 5ff99924 | 2012-11-14 14:59:42 +0000 | [diff] [blame] | 199 | GLIB_AVAILABLE_IN_2_32 |
Ryan Lortie | 08a6d81 | 2011-10-04 20:31:33 -0400 | [diff] [blame] | 200 | void g_rec_mutex_unlock (GRecMutex *rec_mutex); |
Ryan Lortie | ad187e3 | 2011-09-21 14:36:53 -0400 | [diff] [blame] | 201 | |
Will Thompson | 5ff99924 | 2012-11-14 14:59:42 +0000 | [diff] [blame] | 202 | GLIB_AVAILABLE_IN_2_32 |
Ryan Lortie | 08a6d81 | 2011-10-04 20:31:33 -0400 | [diff] [blame] | 203 | void g_cond_init (GCond *cond); |
Will Thompson | 5ff99924 | 2012-11-14 14:59:42 +0000 | [diff] [blame] | 204 | GLIB_AVAILABLE_IN_2_32 |
Ryan Lortie | 08a6d81 | 2011-10-04 20:31:33 -0400 | [diff] [blame] | 205 | void g_cond_clear (GCond *cond); |
Ryan Lortie | 0156092 | 2012-12-06 14:04:59 -0500 | [diff] [blame] | 206 | GLIB_AVAILABLE_IN_ALL |
Ryan Lortie | 08a6d81 | 2011-10-04 20:31:33 -0400 | [diff] [blame] | 207 | void g_cond_wait (GCond *cond, |
| 208 | GMutex *mutex); |
Ryan Lortie | 0156092 | 2012-12-06 14:04:59 -0500 | [diff] [blame] | 209 | GLIB_AVAILABLE_IN_ALL |
Ryan Lortie | 08a6d81 | 2011-10-04 20:31:33 -0400 | [diff] [blame] | 210 | void g_cond_signal (GCond *cond); |
Ryan Lortie | 0156092 | 2012-12-06 14:04:59 -0500 | [diff] [blame] | 211 | GLIB_AVAILABLE_IN_ALL |
Ryan Lortie | 08a6d81 | 2011-10-04 20:31:33 -0400 | [diff] [blame] | 212 | void g_cond_broadcast (GCond *cond); |
Will Thompson | 5ff99924 | 2012-11-14 14:59:42 +0000 | [diff] [blame] | 213 | GLIB_AVAILABLE_IN_2_32 |
Ryan Lortie | 4033c61 | 2011-10-13 23:24:23 -0400 | [diff] [blame] | 214 | gboolean g_cond_wait_until (GCond *cond, |
Ryan Lortie | 08a6d81 | 2011-10-04 20:31:33 -0400 | [diff] [blame] | 215 | GMutex *mutex, |
Matthias Clasen | 117e534 | 2011-10-15 16:50:23 -0400 | [diff] [blame] | 216 | gint64 end_time); |
Ryan Lortie | 80730bc | 2011-09-16 18:05:23 -0400 | [diff] [blame] | 217 | |
Ryan Lortie | 0156092 | 2012-12-06 14:04:59 -0500 | [diff] [blame] | 218 | GLIB_AVAILABLE_IN_ALL |
Ryan Lortie | 08a6d81 | 2011-10-04 20:31:33 -0400 | [diff] [blame] | 219 | gpointer g_private_get (GPrivate *key); |
Ryan Lortie | 0156092 | 2012-12-06 14:04:59 -0500 | [diff] [blame] | 220 | GLIB_AVAILABLE_IN_ALL |
Ryan Lortie | 08a6d81 | 2011-10-04 20:31:33 -0400 | [diff] [blame] | 221 | void g_private_set (GPrivate *key, |
| 222 | gpointer value); |
Will Thompson | 5ff99924 | 2012-11-14 14:59:42 +0000 | [diff] [blame] | 223 | GLIB_AVAILABLE_IN_2_32 |
Ryan Lortie | 08a6d81 | 2011-10-04 20:31:33 -0400 | [diff] [blame] | 224 | void g_private_replace (GPrivate *key, |
| 225 | gpointer value); |
Ryan Lortie | 80730bc | 2011-09-16 18:05:23 -0400 | [diff] [blame] | 226 | |
Ryan Lortie | 0156092 | 2012-12-06 14:04:59 -0500 | [diff] [blame] | 227 | GLIB_AVAILABLE_IN_ALL |
Ryan Lortie | 08a6d81 | 2011-10-04 20:31:33 -0400 | [diff] [blame] | 228 | gpointer g_once_impl (GOnce *once, |
| 229 | GThreadFunc func, |
| 230 | gpointer arg); |
Ryan Lortie | 0156092 | 2012-12-06 14:04:59 -0500 | [diff] [blame] | 231 | GLIB_AVAILABLE_IN_ALL |
Ryan Lortie | 08a6d81 | 2011-10-04 20:31:33 -0400 | [diff] [blame] | 232 | gboolean g_once_init_enter (volatile void *location); |
Ryan Lortie | 0156092 | 2012-12-06 14:04:59 -0500 | [diff] [blame] | 233 | GLIB_AVAILABLE_IN_ALL |
Ryan Lortie | 08a6d81 | 2011-10-04 20:31:33 -0400 | [diff] [blame] | 234 | void g_once_init_leave (volatile void *location, |
| 235 | gsize result); |
| 236 | |
| 237 | #ifdef G_ATOMIC_OP_MEMORY_BARRIER_NEEDED |
| 238 | # define g_once(once, func, arg) g_once_impl ((once), (func), (arg)) |
| 239 | #else /* !G_ATOMIC_OP_MEMORY_BARRIER_NEEDED*/ |
| 240 | # define g_once(once, func, arg) \ |
| 241 | (((once)->status == G_ONCE_STATUS_READY) ? \ |
| 242 | (once)->retval : \ |
| 243 | g_once_impl ((once), (func), (arg))) |
| 244 | #endif /* G_ATOMIC_OP_MEMORY_BARRIER_NEEDED */ |
| 245 | |
| 246 | #ifdef __GNUC__ |
| 247 | # define g_once_init_enter(location) \ |
| 248 | (G_GNUC_EXTENSION ({ \ |
| 249 | G_STATIC_ASSERT (sizeof *(location) == sizeof (gpointer)); \ |
| 250 | (void) (0 ? (gpointer) *(location) : 0); \ |
| 251 | (!g_atomic_pointer_get (location) && \ |
| 252 | g_once_init_enter (location)); \ |
| 253 | })) |
| 254 | # define g_once_init_leave(location, result) \ |
| 255 | (G_GNUC_EXTENSION ({ \ |
| 256 | G_STATIC_ASSERT (sizeof *(location) == sizeof (gpointer)); \ |
| 257 | (void) (0 ? *(location) = (result) : 0); \ |
| 258 | g_once_init_leave ((location), (gsize) (result)); \ |
| 259 | })) |
| 260 | #else |
| 261 | # define g_once_init_enter(location) \ |
| 262 | (g_once_init_enter((location))) |
| 263 | # define g_once_init_leave(location, result) \ |
| 264 | (g_once_init_leave((location), (gsize) (result))) |
| 265 | #endif |
Ryan Lortie | b0d8357 | 2011-09-17 22:00:27 -0400 | [diff] [blame] | 266 | |
Colin Walters | 2149b29 | 2012-12-17 10:47:53 -0500 | [diff] [blame] | 267 | GLIB_AVAILABLE_IN_2_36 |
| 268 | guint g_get_num_processors (void); |
| 269 | |
Xavier Claessens | 1404d3e | 2015-02-05 10:35:42 -0500 | [diff] [blame] | 270 | /** |
| 271 | * GMutexLocker: |
| 272 | * |
| 273 | * Opaque type. See g_mutex_locker_new() for details. |
| 274 | * Since: 2.44 |
| 275 | */ |
| 276 | typedef void GMutexLocker; |
| 277 | |
| 278 | /** |
| 279 | * g_mutex_locker_new: |
| 280 | * @mutex: a mutex to lock |
| 281 | * |
| 282 | * Lock @mutex and return a new #GMutexLocker. Unlock with |
| 283 | * g_mutex_locker_free(). Using g_mutex_unlock() on @mutex |
| 284 | * while a #GMutexLocker exists can lead to undefined behaviour. |
| 285 | * |
| 286 | * This is intended to be used with g_autoptr(). Note that g_autoptr() |
| 287 | * is only available when using GCC or clang, so the following example |
| 288 | * will only work with those compilers: |
| 289 | * |[ |
| 290 | * typedef struct |
| 291 | * { |
| 292 | * ... |
| 293 | * GMutex mutex; |
| 294 | * ... |
| 295 | * } MyObject; |
| 296 | * |
| 297 | * static void |
| 298 | * my_object_do_stuff (MyObject *self) |
| 299 | * { |
| 300 | * g_autoptr(GMutexLocker) locker = g_mutex_locker_new (&self->mutex); |
| 301 | * |
| 302 | * // Code with mutex locked here |
| 303 | * |
| 304 | * if (cond) |
| 305 | * // No need to unlock |
| 306 | * return; |
| 307 | * |
| 308 | * // Optionally early unlock |
| 309 | * g_clear_pointer (&locker, g_mutex_locker_free); |
| 310 | * |
| 311 | * // Code with mutex unlocked here |
| 312 | * } |
| 313 | * ]| |
| 314 | * |
| 315 | * Returns: a #GMutexLocker |
| 316 | * Since: 2.44 |
| 317 | */ |
| 318 | static inline GMutexLocker * |
| 319 | g_mutex_locker_new (GMutex *mutex) |
| 320 | { |
| 321 | g_mutex_lock (mutex); |
| 322 | return (GMutexLocker *) mutex; |
| 323 | } |
| 324 | |
| 325 | /** |
| 326 | * g_mutex_locker_free: |
| 327 | * @locker: a GMutexLocker |
| 328 | * |
| 329 | * Unlock @locker's mutex. See g_mutex_locker_new() for details. |
| 330 | * |
| 331 | * Since: 2.44 |
| 332 | */ |
| 333 | static inline void |
| 334 | g_mutex_locker_free (GMutexLocker *locker) |
| 335 | { |
| 336 | g_mutex_unlock ((GMutex *) locker); |
| 337 | } |
| 338 | |
Sebastian Wilhelmi | b1d1558 | 2000-10-12 11:52:07 +0000 | [diff] [blame] | 339 | G_END_DECLS |
| 340 | |
| 341 | #endif /* __G_THREAD_H__ */ |