gthread-deprecated.c: Include gutils.h
[platform/upstream/glib.git] / glib / deprecated / gthread-deprecated.c
1 /* GLIB - Library of useful routines for C programming
2  * Copyright (C) 1995-1997  Peter Mattis, Spencer Kimball and Josh MacDonald
3  *
4  * gthread.c: MT safety related functions
5  * Copyright 1998 Sebastian Wilhelmi; University of Karlsruhe
6  *                Owen Taylor
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public
10  * License as published by the Free Software Foundation; either
11  * version 2 of the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16  * Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with this library; if not, write to the
20  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21  * Boston, MA 02111-1307, USA.
22  */
23
24 #include "config.h"
25
26 #include "gmessages.h"
27 #include "gslice.h"
28 #include "gmain.h"
29 #include "gthread.h"
30 #include "gthreadprivate.h"
31 #include "deprecated/gthread.h"
32
33 #include "gutils.h"
34
35 /* {{{1 Documentation */
36
37 /**
38  * GThreadPriority:
39  * @G_THREAD_PRIORITY_LOW: a priority lower than normal
40  * @G_THREAD_PRIORITY_NORMAL: the default priority
41  * @G_THREAD_PRIORITY_HIGH: a priority higher than normal
42  * @G_THREAD_PRIORITY_URGENT: the highest priority
43  *
44  * Deprecated:2.32: Thread priorities no longer have any effect.
45  */
46
47 /**
48  * GThreadFunctions:
49  * @mutex_new: virtual function pointer for g_mutex_new()
50  * @mutex_lock: virtual function pointer for g_mutex_lock()
51  * @mutex_trylock: virtual function pointer for g_mutex_trylock()
52  * @mutex_unlock: virtual function pointer for g_mutex_unlock()
53  * @mutex_free: virtual function pointer for g_mutex_free()
54  * @cond_new: virtual function pointer for g_cond_new()
55  * @cond_signal: virtual function pointer for g_cond_signal()
56  * @cond_broadcast: virtual function pointer for g_cond_broadcast()
57  * @cond_wait: virtual function pointer for g_cond_wait()
58  * @cond_timed_wait: virtual function pointer for g_cond_timed_wait()
59  * @cond_free: virtual function pointer for g_cond_free()
60  * @private_new: virtual function pointer for g_private_new()
61  * @private_get: virtual function pointer for g_private_get()
62  * @private_set: virtual function pointer for g_private_set()
63  * @thread_create: virtual function pointer for g_thread_create()
64  * @thread_yield: virtual function pointer for g_thread_yield()
65  * @thread_join: virtual function pointer for g_thread_join()
66  * @thread_exit: virtual function pointer for g_thread_exit()
67  * @thread_set_priority: virtual function pointer for
68  *                       g_thread_set_priority()
69  * @thread_self: virtual function pointer for g_thread_self()
70  * @thread_equal: used internally by recursive mutex locks and by some
71  *                assertion checks
72  *
73  * This function table is no longer used by g_thread_init()
74  * to initialize the thread system.
75  */
76
77 /* {{{1 Exported Variables */
78
79 gboolean g_thread_use_default_impl = TRUE;
80
81 GThreadFunctions g_thread_functions_for_glib_use =
82 {
83   g_mutex_new,
84   g_mutex_lock,
85   g_mutex_trylock,
86   g_mutex_unlock,
87   g_mutex_free,
88   g_cond_new,
89   g_cond_signal,
90   g_cond_broadcast,
91   g_cond_wait,
92   g_cond_timed_wait,
93   g_cond_free,
94   g_private_new,
95   g_private_get,
96   g_private_set,
97   NULL,
98   g_thread_yield,
99   NULL,
100   NULL,
101   NULL,
102   NULL,
103   NULL,
104 };
105
106 static guint64
107 gettime (void)
108 {
109   return g_get_monotonic_time () * 1000;
110 }
111
112 guint64 (*g_thread_gettime) (void) = gettime;
113
114 /* Initialisation {{{1 ---------------------------------------------------- */
115 gboolean         g_threads_got_initialized = TRUE;
116 GSystemThread    zero_thread; /* This is initialized to all zero */
117
118
119 /**
120  * g_thread_init:
121  * @vtable: a function table of type #GThreadFunctions, that provides
122  *     the entry points to the thread system to be used. Since 2.32,
123  *     this parameter is ignored and should always be %NULL
124  *
125  * If you use GLib from more than one thread, you must initialize the
126  * thread system by calling g_thread_init().
127  *
128  * Since version 2.24, calling g_thread_init() multiple times is allowed,
129  * but nothing happens except for the first call.
130  *
131  * Since version 2.32, GLib does not support custom thread implementations
132  * anymore and the @vtable parameter is ignored and you should pass %NULL.
133  *
134  * <note><para>g_thread_init() must not be called directly or indirectly
135  * in a callback from GLib. Also no mutexes may be currently locked while
136  * calling g_thread_init().</para></note>
137  *
138  * <note><para>To use g_thread_init() in your program, you have to link
139  * with the libraries that the command <command>pkg-config --libs
140  * gthread-2.0</command> outputs. This is not the case for all the
141  * other thread-related functions of GLib. Those can be used without
142  * having to link with the thread libraries.</para></note>
143  */
144
145 /**
146  * g_thread_get_initialized:
147  *
148  * Indicates if g_thread_init() has been called.
149  *
150  * Returns: %TRUE if threads have been initialized.
151  *
152  * Since: 2.20
153  */
154 gboolean
155 g_thread_get_initialized (void)
156 {
157   return g_thread_supported ();
158 }
159
160 /* We need this for ABI compatibility */
161 void g_thread_init_glib (void) { }
162
163 /* Internal variables {{{1 */
164
165 static GRealThread *g_thread_all_threads = NULL;
166 static GSList      *g_thread_free_indices = NULL;
167
168 /* Protects g_thread_all_threads and g_thread_free_indices */
169 G_LOCK_DEFINE_STATIC (g_thread);
170
171 /* Misc. GThread functions {{{1 */
172
173 /**
174  * g_thread_set_priority:
175  * @thread: a #GThread.
176  * @priority: ignored
177  *
178  * This function does nothing.
179  *
180  * Deprecated:2.32: Thread priorities no longer have any effect.
181  */
182 void
183 g_thread_set_priority (GThread         *thread,
184                        GThreadPriority  priority)
185 {
186 }
187
188 /**
189  * g_thread_create:
190  * @func: a function to execute in the new thread
191  * @data: an argument to supply to the new thread
192  * @joinable: should this thread be joinable?
193  * @error: return location for error, or %NULL
194  *
195  * This function creates a new thread.
196  *
197  * If @joinable is %TRUE, you can wait for this threads termination
198  * calling g_thread_join(). Otherwise the thread will just disappear
199  * when it terminates.
200  *
201  * The new thread executes the function @func with the argument @data.
202  * If the thread was created successfully, it is returned.
203  *
204  * @error can be %NULL to ignore errors, or non-%NULL to report errors.
205  * The error is set, if and only if the function returns %NULL.
206  *
207  * Returns: the new #GThread on success
208  *
209  * Deprecated:2.32: Use g_thread_new() instead
210  */
211 GThread *
212 g_thread_create (GThreadFunc   func,
213                  gpointer      data,
214                  gboolean      joinable,
215                  GError      **error)
216 {
217   return g_thread_new_internal (NULL, func, data, joinable, 0, TRUE, error);
218 }
219
220 /**
221  * g_thread_create_full:
222  * @func: a function to execute in the new thread.
223  * @data: an argument to supply to the new thread.
224  * @stack_size: a stack size for the new thread.
225  * @joinable: should this thread be joinable?
226  * @bound: ignored
227  * @priority: ignored
228  * @error: return location for error.
229  * @Returns: the new #GThread on success.
230  *
231  * This function creates a new thread.
232  *
233  * Deprecated:2.32: The @bound and @priority arguments are now ignored.
234  * Use g_thread_new() or g_thread_new_full() instead.
235  */
236 GThread *
237 g_thread_create_full (GThreadFunc       func,
238                       gpointer          data,
239                       gulong            stack_size,
240                       gboolean          joinable,
241                       gboolean          bound,
242                       GThreadPriority   priority,
243                       GError          **error)
244 {
245   return g_thread_new_internal (NULL, func, data, joinable, stack_size, TRUE, error);
246 }
247
248 /**
249  * g_thread_foreach:
250  * @thread_func: function to call for all #GThread structures
251  * @user_data: second argument to @thread_func
252  *
253  * Call @thread_func on all #GThreads that have been
254  * created with g_thread_create().
255  *
256  * Note that threads may decide to exit while @thread_func is
257  * running, so without intimate knowledge about the lifetime of
258  * foreign threads, @thread_func shouldn't access the GThread*
259  * pointer passed in as first argument. However, @thread_func will
260  * not be called for threads which are known to have exited already.
261  *
262  * Due to thread lifetime checks, this function has an execution complexity
263  * which is quadratic in the number of existing threads.
264  *
265  * Since: 2.10
266  *
267  * Deprecated:2.32: There aren't many things you can do with a #GThread,
268  *     except comparing it with one that was returned from g_thread_create().
269  *     There are better ways to find out if your thread is still alive.
270  */
271 void
272 g_thread_foreach (GFunc    thread_func,
273                   gpointer user_data)
274 {
275   GSList *slist = NULL;
276   GRealThread *thread;
277   g_return_if_fail (thread_func != NULL);
278   /* snapshot the list of threads for iteration */
279   G_LOCK (g_thread);
280   for (thread = g_thread_all_threads; thread; thread = thread->next)
281     slist = g_slist_prepend (slist, thread);
282   G_UNLOCK (g_thread);
283   /* walk the list, skipping non-existent threads */
284   while (slist)
285     {
286       GSList *node = slist;
287       slist = node->next;
288       /* check whether the current thread still exists */
289       G_LOCK (g_thread);
290       for (thread = g_thread_all_threads; thread; thread = thread->next)
291         if (thread == node->data)
292           break;
293       G_UNLOCK (g_thread);
294       if (thread)
295         thread_func (thread, user_data);
296       g_slist_free_1 (node);
297     }
298 }
299
300 void
301 g_enumerable_thread_add (GRealThread *thread)
302 {
303   G_LOCK (g_thread);
304   thread->next = g_thread_all_threads;
305   g_thread_all_threads = thread;
306   G_UNLOCK (g_thread);
307 }
308
309 void
310 g_enumerable_thread_remove (GRealThread *thread)
311 {
312   GRealThread *t, *p;
313
314   G_LOCK (g_thread);
315   for (t = g_thread_all_threads, p = NULL; t; p = t, t = t->next)
316     {
317       if (t == thread)
318         {
319           if (p)
320             p->next = t->next;
321           else
322             g_thread_all_threads = t->next;
323           break;
324         }
325     }
326   G_UNLOCK (g_thread);
327 }
328
329 /* GOnce {{{1 ------------------------------------------------------------- */
330 gboolean
331 g_once_init_enter_impl (volatile gsize *location)
332 {
333   return (g_once_init_enter) (location);
334 }
335
336 /* GStaticMutex {{{1 ------------------------------------------------------ */
337
338 /**
339  * GStaticMutex:
340  *
341  * A #GStaticMutex works like a #GMutex.
342  *
343  * Prior to GLib 2.32, GStaticMutex had the significant advantage
344  * that it doesn't need to be created at run-time, but can be defined
345  * at compile-time. Since 2.32, #GMutex can be statically allocated
346  * as well, and GStaticMutex has been deprecated.
347  *
348  * Here is a version of our give_me_next_number() example using
349  * a GStaticMutex.
350  *
351  * <example>
352  *  <title>
353  *   Using <structname>GStaticMutex</structname>
354  *   to simplify thread-safe programming
355  *  </title>
356  *  <programlisting>
357  *   int
358  *   give_me_next_number (void)
359  *   {
360  *     static int current_number = 0;
361  *     int ret_val;
362  *     static GStaticMutex mutex = G_STATIC_MUTEX_INIT;
363  *
364  *     g_static_mutex_lock (&amp;mutex);
365  *     ret_val = current_number = calc_next_number (current_number);
366  *     g_static_mutex_unlock (&amp;mutex);
367  *
368  *     return ret_val;
369  *   }
370  *  </programlisting>
371  * </example>
372  *
373  * Sometimes you would like to dynamically create a mutex. If you don't
374  * want to require prior calling to g_thread_init(), because your code
375  * should also be usable in non-threaded programs, you are not able to
376  * use g_mutex_new() and thus #GMutex, as that requires a prior call to
377  * g_thread_init(). In theses cases you can also use a #GStaticMutex.
378  * It must be initialized with g_static_mutex_init() before using it
379  * and freed with with g_static_mutex_free() when not needed anymore to
380  * free up any allocated resources.
381  *
382  * Even though #GStaticMutex is not opaque, it should only be used with
383  * the following functions, as it is defined differently on different
384  * platforms.
385  *
386  * All of the <function>g_static_mutex_*</function> functions apart
387  * from <function>g_static_mutex_get_mutex</function> can also be used
388  * even if g_thread_init() has not yet been called. Then they do
389  * nothing, apart from <function>g_static_mutex_trylock</function>,
390  * which does nothing but returning %TRUE.
391  *
392  * <note><para>All of the <function>g_static_mutex_*</function>
393  * functions are actually macros. Apart from taking their addresses, you
394  * can however use them as if they were functions.</para></note>
395  **/
396
397 /**
398  * G_STATIC_MUTEX_INIT:
399  *
400  * A #GStaticMutex must be initialized with this macro, before it can
401  * be used. This macro can used be to initialize a variable, but it
402  * cannot be assigned to a variable. In that case you have to use
403  * g_static_mutex_init().
404  *
405  * |[
406  * GStaticMutex my_mutex = G_STATIC_MUTEX_INIT;
407  * ]|
408  **/
409
410 /**
411  * g_static_mutex_init:
412  * @mutex: a #GStaticMutex to be initialized.
413  *
414  * Initializes @mutex.
415  * Alternatively you can initialize it with #G_STATIC_MUTEX_INIT.
416  *
417  * Deprecated: 2.32: Use g_mutex_init()
418  */
419 void
420 g_static_mutex_init (GStaticMutex *mutex)
421 {
422   static const GStaticMutex init_mutex = G_STATIC_MUTEX_INIT;
423
424   g_return_if_fail (mutex);
425
426   *mutex = init_mutex;
427 }
428
429 /* IMPLEMENTATION NOTE:
430  *
431  * On some platforms a GStaticMutex is actually a normal GMutex stored
432  * inside of a structure instead of being allocated dynamically.  We can
433  * only do this for platforms on which we know, in advance, how to
434  * allocate (size) and initialise (value) that memory.
435  *
436  * On other platforms, a GStaticMutex is nothing more than a pointer to
437  * a GMutex.  In that case, the first access we make to the static mutex
438  * must first allocate the normal GMutex and store it into the pointer.
439  *
440  * configure.ac writes macros into glibconfig.h to determine if
441  * g_static_mutex_get_mutex() accesses the structure in memory directly
442  * (on platforms where we are able to do that) or if it ends up here,
443  * where we may have to allocate the GMutex before returning it.
444  */
445
446 /**
447  * g_static_mutex_get_mutex:
448  * @mutex: a #GStaticMutex.
449  * @Returns: the #GMutex corresponding to @mutex.
450  *
451  * For some operations (like g_cond_wait()) you must have a #GMutex
452  * instead of a #GStaticMutex. This function will return the
453  * corresponding #GMutex for @mutex.
454  *
455  * Deprecated: 2.32: Just use a #GMutex
456  */
457 GMutex *
458 g_static_mutex_get_mutex_impl (GMutex** mutex)
459 {
460   GMutex *result;
461
462   if (!g_thread_supported ())
463     return NULL;
464
465   result = g_atomic_pointer_get (mutex);
466
467   if (!result)
468     {
469       g_mutex_lock (&g_once_mutex);
470
471       result = *mutex;
472       if (!result)
473         {
474           result = g_mutex_new ();
475           g_atomic_pointer_set (mutex, result);
476         }
477
478       g_mutex_unlock (&g_once_mutex);
479     }
480
481   return result;
482 }
483
484 /* IMPLEMENTATION NOTE:
485  *
486  * g_static_mutex_lock(), g_static_mutex_trylock() and
487  * g_static_mutex_unlock() are all preprocessor macros that wrap the
488  * corresponding g_mutex_*() function around a call to
489  * g_static_mutex_get_mutex().
490  */
491
492 /**
493  * g_static_mutex_lock:
494  * @mutex: a #GStaticMutex.
495  *
496  * Works like g_mutex_lock(), but for a #GStaticMutex.
497  *
498  * Deprecated: 2.32: Use g_mutex_lock()
499  */
500
501 /**
502  * g_static_mutex_trylock:
503  * @mutex: a #GStaticMutex.
504  * @Returns: %TRUE, if the #GStaticMutex could be locked.
505  *
506  * Works like g_mutex_trylock(), but for a #GStaticMutex.
507  *
508  * Deprecated: 2.32: Use g_mutex_trylock()
509  */
510
511 /**
512  * g_static_mutex_unlock:
513  * @mutex: a #GStaticMutex.
514  *
515  * Works like g_mutex_unlock(), but for a #GStaticMutex.
516  *
517  * Deprecated: 2.32: Use g_mutex_unlock()
518  */
519
520 /**
521  * g_static_mutex_free:
522  * @mutex: a #GStaticMutex to be freed.
523  *
524  * Releases all resources allocated to @mutex.
525  *
526  * You don't have to call this functions for a #GStaticMutex with an
527  * unbounded lifetime, i.e. objects declared 'static', but if you have
528  * a #GStaticMutex as a member of a structure and the structure is
529  * freed, you should also free the #GStaticMutex.
530  *
531  * <note><para>Calling g_static_mutex_free() on a locked mutex may
532  * result in undefined behaviour.</para></note>
533  *
534  * Deprecated: 2.32: Use g_mutex_free()
535  */
536 void
537 g_static_mutex_free (GStaticMutex* mutex)
538 {
539   GMutex **runtime_mutex;
540
541   g_return_if_fail (mutex);
542
543   /* The runtime_mutex is the first (or only) member of GStaticMutex,
544    * see both versions (of glibconfig.h) in configure.ac. Note, that
545    * this variable is NULL, if g_thread_init() hasn't been called or
546    * if we're using the default thread implementation and it provides
547    * static mutexes. */
548   runtime_mutex = ((GMutex**)mutex);
549
550   if (*runtime_mutex)
551     g_mutex_free (*runtime_mutex);
552
553   *runtime_mutex = NULL;
554 }
555
556 /* {{{1 GStaticRecMutex */
557
558 /**
559  * GStaticRecMutex:
560  *
561  * A #GStaticRecMutex works like a #GStaticMutex, but it can be locked
562  * multiple times by one thread. If you enter it n times, you have to
563  * unlock it n times again to let other threads lock it. An exception
564  * is the function g_static_rec_mutex_unlock_full(): that allows you to
565  * unlock a #GStaticRecMutex completely returning the depth, (i.e. the
566  * number of times this mutex was locked). The depth can later be used
567  * to restore the state of the #GStaticRecMutex by calling
568  * g_static_rec_mutex_lock_full(). In GLib 2.32, #GStaticRecMutex has
569  * been deprecated in favor of #GRecMutex.
570  *
571  * Even though #GStaticRecMutex is not opaque, it should only be used
572  * with the following functions.
573  *
574  * All of the <function>g_static_rec_mutex_*</function> functions can
575  * be used even if g_thread_init() has not been called. Then they do
576  * nothing, apart from <function>g_static_rec_mutex_trylock</function>,
577  * which does nothing but returning %TRUE.
578  **/
579
580 /**
581  * G_STATIC_REC_MUTEX_INIT:
582  *
583  * A #GStaticRecMutex must be initialized with this macro before it can
584  * be used. This macro can used be to initialize a variable, but it
585  * cannot be assigned to a variable. In that case you have to use
586  * g_static_rec_mutex_init().
587  *
588  * |[
589  *   GStaticRecMutex my_mutex = G_STATIC_REC_MUTEX_INIT;
590  * ]|
591  */
592
593 /**
594  * g_static_rec_mutex_init:
595  * @mutex: a #GStaticRecMutex to be initialized.
596  *
597  * A #GStaticRecMutex must be initialized with this function before it
598  * can be used. Alternatively you can initialize it with
599  * #G_STATIC_REC_MUTEX_INIT.
600  *
601  * Deprecated: 2.32: Use g_rec_mutex_init()
602  */
603 void
604 g_static_rec_mutex_init (GStaticRecMutex *mutex)
605 {
606   static const GStaticRecMutex init_mutex = G_STATIC_REC_MUTEX_INIT;
607
608   g_return_if_fail (mutex);
609
610   *mutex = init_mutex;
611 }
612
613 /**
614  * g_static_rec_mutex_lock:
615  * @mutex: a #GStaticRecMutex to lock.
616  *
617  * Locks @mutex. If @mutex is already locked by another thread, the
618  * current thread will block until @mutex is unlocked by the other
619  * thread. If @mutex is already locked by the calling thread, this
620  * functions increases the depth of @mutex and returns immediately.
621  *
622  * Deprecated: 2.32: Use g_rec_mutex_lock()
623  */
624 void
625 g_static_rec_mutex_lock (GStaticRecMutex* mutex)
626 {
627   GSystemThread self;
628
629   g_return_if_fail (mutex);
630
631   if (!g_thread_supported ())
632     return;
633
634   g_system_thread_self (&self);
635
636   if (g_system_thread_equal (&self, &mutex->owner))
637     {
638       mutex->depth++;
639       return;
640     }
641   g_static_mutex_lock (&mutex->mutex);
642   g_system_thread_assign (mutex->owner, self);
643   mutex->depth = 1;
644 }
645
646 /**
647  * g_static_rec_mutex_trylock:
648  * @mutex: a #GStaticRecMutex to lock.
649  * @Returns: %TRUE, if @mutex could be locked.
650  *
651  * Tries to lock @mutex. If @mutex is already locked by another thread,
652  * it immediately returns %FALSE. Otherwise it locks @mutex and returns
653  * %TRUE. If @mutex is already locked by the calling thread, this
654  * functions increases the depth of @mutex and immediately returns
655  * %TRUE.
656  *
657  * Deprecated: 2.32: Use g_rec_mutex_trylock()
658  */
659 gboolean
660 g_static_rec_mutex_trylock (GStaticRecMutex* mutex)
661 {
662   GSystemThread self;
663
664   g_return_val_if_fail (mutex, FALSE);
665
666   if (!g_thread_supported ())
667     return TRUE;
668
669   g_system_thread_self (&self);
670
671   if (g_system_thread_equal (&self, &mutex->owner))
672     {
673       mutex->depth++;
674       return TRUE;
675     }
676
677   if (!g_static_mutex_trylock (&mutex->mutex))
678     return FALSE;
679
680   g_system_thread_assign (mutex->owner, self);
681   mutex->depth = 1;
682   return TRUE;
683 }
684
685 /**
686  * g_static_rec_mutex_unlock:
687  * @mutex: a #GStaticRecMutex to unlock.
688  *
689  * Unlocks @mutex. Another thread will be allowed to lock @mutex only
690  * when it has been unlocked as many times as it had been locked
691  * before. If @mutex is completely unlocked and another thread is
692  * blocked in a g_static_rec_mutex_lock() call for @mutex, it will be
693  * woken and can lock @mutex itself.
694  *
695  * Deprecated: 2.32: Use g_rec_mutex_unlock()
696  */
697 void
698 g_static_rec_mutex_unlock (GStaticRecMutex* mutex)
699 {
700   g_return_if_fail (mutex);
701
702   if (!g_thread_supported ())
703     return;
704
705   if (mutex->depth > 1)
706     {
707       mutex->depth--;
708       return;
709     }
710   g_system_thread_assign (mutex->owner, zero_thread);
711   g_static_mutex_unlock (&mutex->mutex);
712 }
713
714 /**
715  * g_static_rec_mutex_lock_full:
716  * @mutex: a #GStaticRecMutex to lock.
717  * @depth: number of times this mutex has to be unlocked to be
718  *         completely unlocked.
719  *
720  * Works like calling g_static_rec_mutex_lock() for @mutex @depth times.
721  *
722  * Deprecated: 2.32: Use g_rec_mutex_lock()
723  */
724 void
725 g_static_rec_mutex_lock_full (GStaticRecMutex *mutex,
726                               guint            depth)
727 {
728   GSystemThread self;
729   g_return_if_fail (mutex);
730
731   if (!g_thread_supported ())
732     return;
733
734   if (depth == 0)
735     return;
736
737   g_system_thread_self (&self);
738
739   if (g_system_thread_equal (&self, &mutex->owner))
740     {
741       mutex->depth += depth;
742       return;
743     }
744   g_static_mutex_lock (&mutex->mutex);
745   g_system_thread_assign (mutex->owner, self);
746   mutex->depth = depth;
747 }
748
749 /**
750  * g_static_rec_mutex_unlock_full:
751  * @mutex: a #GStaticRecMutex to completely unlock.
752  * @Returns: number of times @mutex has been locked by the current
753  *           thread.
754  *
755  * Completely unlocks @mutex. If another thread is blocked in a
756  * g_static_rec_mutex_lock() call for @mutex, it will be woken and can
757  * lock @mutex itself. This function returns the number of times that
758  * @mutex has been locked by the current thread. To restore the state
759  * before the call to g_static_rec_mutex_unlock_full() you can call
760  * g_static_rec_mutex_lock_full() with the depth returned by this
761  * function.
762  *
763  * Deprecated: 2.32: Use g_rec_mutex_unlock()
764  */
765 guint
766 g_static_rec_mutex_unlock_full (GStaticRecMutex *mutex)
767 {
768   guint depth;
769
770   g_return_val_if_fail (mutex, 0);
771
772   if (!g_thread_supported ())
773     return 1;
774
775   depth = mutex->depth;
776
777   g_system_thread_assign (mutex->owner, zero_thread);
778   mutex->depth = 0;
779   g_static_mutex_unlock (&mutex->mutex);
780
781   return depth;
782 }
783
784 /**
785  * g_static_rec_mutex_free:
786  * @mutex: a #GStaticRecMutex to be freed.
787  *
788  * Releases all resources allocated to a #GStaticRecMutex.
789  *
790  * You don't have to call this functions for a #GStaticRecMutex with an
791  * unbounded lifetime, i.e. objects declared 'static', but if you have
792  * a #GStaticRecMutex as a member of a structure and the structure is
793  * freed, you should also free the #GStaticRecMutex.
794  *
795  * Deprecated: 2.32: Use g_rec_mutex_clear()
796  */
797 void
798 g_static_rec_mutex_free (GStaticRecMutex *mutex)
799 {
800   g_return_if_fail (mutex);
801
802   g_static_mutex_free (&mutex->mutex);
803 }
804
805 /* GStaticRWLock {{{1 ----------------------------------------------------- */
806
807 /**
808  * GStaticRWLock:
809  *
810  * The #GStaticRWLock struct represents a read-write lock. A read-write
811  * lock can be used for protecting data that some portions of code only
812  * read from, while others also write. In such situations it is
813  * desirable that several readers can read at once, whereas of course
814  * only one writer may write at a time. Take a look at the following
815  * example:
816  *
817  * <example>
818  *  <title>An array with access functions</title>
819  *  <programlisting>
820  *   GStaticRWLock rwlock = G_STATIC_RW_LOCK_INIT;
821  *   GPtrArray *array;
822  *
823  *   gpointer
824  *   my_array_get (guint index)
825  *   {
826  *     gpointer retval = NULL;
827  *
828  *     if (!array)
829  *       return NULL;
830  *
831  *     g_static_rw_lock_reader_lock (&amp;rwlock);
832  *     if (index &lt; array->len)
833  *       retval = g_ptr_array_index (array, index);
834  *     g_static_rw_lock_reader_unlock (&amp;rwlock);
835  *
836  *     return retval;
837  *   }
838  *
839  *   void
840  *   my_array_set (guint index, gpointer data)
841  *   {
842  *     g_static_rw_lock_writer_lock (&amp;rwlock);
843  *
844  *     if (!array)
845  *       array = g_ptr_array_new (<!-- -->);
846  *
847  *     if (index >= array->len)
848  *       g_ptr_array_set_size (array, index+1);
849  *     g_ptr_array_index (array, index) = data;
850  *
851  *     g_static_rw_lock_writer_unlock (&amp;rwlock);
852  *   }
853  *  </programlisting>
854  * </example>
855  *
856  * This example shows an array which can be accessed by many readers
857  * (the <function>my_array_get()</function> function) simultaneously,
858  * whereas the writers (the <function>my_array_set()</function>
859  * function) will only be allowed once at a time and only if no readers
860  * currently access the array. This is because of the potentially
861  * dangerous resizing of the array. Using these functions is fully
862  * multi-thread safe now.
863  *
864  * Most of the time, writers should have precedence over readers. That
865  * means, for this implementation, that as soon as a writer wants to
866  * lock the data, no other reader is allowed to lock the data, whereas,
867  * of course, the readers that already have locked the data are allowed
868  * to finish their operation. As soon as the last reader unlocks the
869  * data, the writer will lock it.
870  *
871  * Even though #GStaticRWLock is not opaque, it should only be used
872  * with the following functions.
873  *
874  * All of the <function>g_static_rw_lock_*</function> functions can be
875  * used even if g_thread_init() has not been called. Then they do
876  * nothing, apart from <function>g_static_rw_lock_*_trylock</function>,
877  * which does nothing but returning %TRUE.
878  *
879  * <note><para>A read-write lock has a higher overhead than a mutex. For
880  * example, both g_static_rw_lock_reader_lock() and
881  * g_static_rw_lock_reader_unlock() have to lock and unlock a
882  * #GStaticMutex, so it takes at least twice the time to lock and unlock
883  * a #GStaticRWLock that it does to lock and unlock a #GStaticMutex. So
884  * only data structures that are accessed by multiple readers, and which
885  * keep the lock for a considerable time justify a #GStaticRWLock. The
886  * above example most probably would fare better with a
887  * #GStaticMutex.</para></note>
888  *
889  * Deprecated: 2.32: Use a #GRWLock instead
890  **/
891
892 /**
893  * G_STATIC_RW_LOCK_INIT:
894  *
895  * A #GStaticRWLock must be initialized with this macro before it can
896  * be used. This macro can used be to initialize a variable, but it
897  * cannot be assigned to a variable. In that case you have to use
898  * g_static_rw_lock_init().
899  *
900  * |[
901  *   GStaticRWLock my_lock = G_STATIC_RW_LOCK_INIT;
902  * ]|
903  */
904
905 /**
906  * g_static_rw_lock_init:
907  * @lock: a #GStaticRWLock to be initialized.
908  *
909  * A #GStaticRWLock must be initialized with this function before it
910  * can be used. Alternatively you can initialize it with
911  * #G_STATIC_RW_LOCK_INIT.
912  *
913  * Deprecated: 2.32: Use g_rw_lock_init() instead
914  */
915 void
916 g_static_rw_lock_init (GStaticRWLock* lock)
917 {
918   static const GStaticRWLock init_lock = G_STATIC_RW_LOCK_INIT;
919
920   g_return_if_fail (lock);
921
922   *lock = init_lock;
923 }
924
925 inline static void
926 g_static_rw_lock_wait (GCond** cond, GStaticMutex* mutex)
927 {
928   if (!*cond)
929       *cond = g_cond_new ();
930   g_cond_wait (*cond, g_static_mutex_get_mutex (mutex));
931 }
932
933 inline static void
934 g_static_rw_lock_signal (GStaticRWLock* lock)
935 {
936   if (lock->want_to_write && lock->write_cond)
937     g_cond_signal (lock->write_cond);
938   else if (lock->want_to_read && lock->read_cond)
939     g_cond_broadcast (lock->read_cond);
940 }
941
942 /**
943  * g_static_rw_lock_reader_lock:
944  * @lock: a #GStaticRWLock to lock for reading.
945  *
946  * Locks @lock for reading. There may be unlimited concurrent locks for
947  * reading of a #GStaticRWLock at the same time.  If @lock is already
948  * locked for writing by another thread or if another thread is already
949  * waiting to lock @lock for writing, this function will block until
950  * @lock is unlocked by the other writing thread and no other writing
951  * threads want to lock @lock. This lock has to be unlocked by
952  * g_static_rw_lock_reader_unlock().
953  *
954  * #GStaticRWLock is not recursive. It might seem to be possible to
955  * recursively lock for reading, but that can result in a deadlock, due
956  * to writer preference.
957  *
958  * Deprecated: 2.32: Use g_rw_lock_reader_lock() instead
959  */
960 void
961 g_static_rw_lock_reader_lock (GStaticRWLock* lock)
962 {
963   g_return_if_fail (lock);
964
965   if (!g_threads_got_initialized)
966     return;
967
968   g_static_mutex_lock (&lock->mutex);
969   lock->want_to_read++;
970   while (lock->have_writer || lock->want_to_write)
971     g_static_rw_lock_wait (&lock->read_cond, &lock->mutex);
972   lock->want_to_read--;
973   lock->read_counter++;
974   g_static_mutex_unlock (&lock->mutex);
975 }
976
977 /**
978  * g_static_rw_lock_reader_trylock:
979  * @lock: a #GStaticRWLock to lock for reading.
980  * @Returns: %TRUE, if @lock could be locked for reading.
981  *
982  * Tries to lock @lock for reading. If @lock is already locked for
983  * writing by another thread or if another thread is already waiting to
984  * lock @lock for writing, immediately returns %FALSE. Otherwise locks
985  * @lock for reading and returns %TRUE. This lock has to be unlocked by
986  * g_static_rw_lock_reader_unlock().
987  *
988  * Deprectated: 2.32: Use g_rw_lock_reader_trylock() instead
989  */
990 gboolean
991 g_static_rw_lock_reader_trylock (GStaticRWLock* lock)
992 {
993   gboolean ret_val = FALSE;
994
995   g_return_val_if_fail (lock, FALSE);
996
997   if (!g_threads_got_initialized)
998     return TRUE;
999
1000   g_static_mutex_lock (&lock->mutex);
1001   if (!lock->have_writer && !lock->want_to_write)
1002     {
1003       lock->read_counter++;
1004       ret_val = TRUE;
1005     }
1006   g_static_mutex_unlock (&lock->mutex);
1007   return ret_val;
1008 }
1009
1010 /**
1011  * g_static_rw_lock_reader_unlock:
1012  * @lock: a #GStaticRWLock to unlock after reading.
1013  *
1014  * Unlocks @lock. If a thread waits to lock @lock for writing and all
1015  * locks for reading have been unlocked, the waiting thread is woken up
1016  * and can lock @lock for writing.
1017  *
1018  * Deprectated: 2.32: Use g_rw_lock_reader_unlock() instead
1019  */
1020 void
1021 g_static_rw_lock_reader_unlock  (GStaticRWLock* lock)
1022 {
1023   g_return_if_fail (lock);
1024
1025   if (!g_threads_got_initialized)
1026     return;
1027
1028   g_static_mutex_lock (&lock->mutex);
1029   lock->read_counter--;
1030   if (lock->read_counter == 0)
1031     g_static_rw_lock_signal (lock);
1032   g_static_mutex_unlock (&lock->mutex);
1033 }
1034
1035 /**
1036  * g_static_rw_lock_writer_lock:
1037  * @lock: a #GStaticRWLock to lock for writing.
1038  *
1039  * Locks @lock for writing. If @lock is already locked for writing or
1040  * reading by other threads, this function will block until @lock is
1041  * completely unlocked and then lock @lock for writing. While this
1042  * functions waits to lock @lock, no other thread can lock @lock for
1043  * reading. When @lock is locked for writing, no other thread can lock
1044  * @lock (neither for reading nor writing). This lock has to be
1045  * unlocked by g_static_rw_lock_writer_unlock().
1046  *
1047  * Deprectated: 2.32: Use g_rw_lock_writer_lock() instead
1048  */
1049 void
1050 g_static_rw_lock_writer_lock (GStaticRWLock* lock)
1051 {
1052   g_return_if_fail (lock);
1053
1054   if (!g_threads_got_initialized)
1055     return;
1056
1057   g_static_mutex_lock (&lock->mutex);
1058   lock->want_to_write++;
1059   while (lock->have_writer || lock->read_counter)
1060     g_static_rw_lock_wait (&lock->write_cond, &lock->mutex);
1061   lock->want_to_write--;
1062   lock->have_writer = TRUE;
1063   g_static_mutex_unlock (&lock->mutex);
1064 }
1065
1066 /**
1067  * g_static_rw_lock_writer_trylock:
1068  * @lock: a #GStaticRWLock to lock for writing.
1069  * @Returns: %TRUE, if @lock could be locked for writing.
1070  *
1071  * Tries to lock @lock for writing. If @lock is already locked (for
1072  * either reading or writing) by another thread, it immediately returns
1073  * %FALSE. Otherwise it locks @lock for writing and returns %TRUE. This
1074  * lock has to be unlocked by g_static_rw_lock_writer_unlock().
1075  *
1076  * Deprectated: 2.32: Use g_rw_lock_writer_trylock() instead
1077  */
1078 gboolean
1079 g_static_rw_lock_writer_trylock (GStaticRWLock* lock)
1080 {
1081   gboolean ret_val = FALSE;
1082
1083   g_return_val_if_fail (lock, FALSE);
1084
1085   if (!g_threads_got_initialized)
1086     return TRUE;
1087
1088   g_static_mutex_lock (&lock->mutex);
1089   if (!lock->have_writer && !lock->read_counter)
1090     {
1091       lock->have_writer = TRUE;
1092       ret_val = TRUE;
1093     }
1094   g_static_mutex_unlock (&lock->mutex);
1095   return ret_val;
1096 }
1097
1098 /**
1099  * g_static_rw_lock_writer_unlock:
1100  * @lock: a #GStaticRWLock to unlock after writing.
1101  *
1102  * Unlocks @lock. If a thread is waiting to lock @lock for writing and
1103  * all locks for reading have been unlocked, the waiting thread is
1104  * woken up and can lock @lock for writing. If no thread is waiting to
1105  * lock @lock for writing, and some thread or threads are waiting to
1106  * lock @lock for reading, the waiting threads are woken up and can
1107  * lock @lock for reading.
1108  *
1109  * Deprectated: 2.32: Use g_rw_lock_writer_unlock() instead
1110  */
1111 void
1112 g_static_rw_lock_writer_unlock (GStaticRWLock* lock)
1113 {
1114   g_return_if_fail (lock);
1115
1116   if (!g_threads_got_initialized)
1117     return;
1118
1119   g_static_mutex_lock (&lock->mutex);
1120   lock->have_writer = FALSE;
1121   g_static_rw_lock_signal (lock);
1122   g_static_mutex_unlock (&lock->mutex);
1123 }
1124
1125 /**
1126  * g_static_rw_lock_free:
1127  * @lock: a #GStaticRWLock to be freed.
1128  *
1129  * Releases all resources allocated to @lock.
1130  *
1131  * You don't have to call this functions for a #GStaticRWLock with an
1132  * unbounded lifetime, i.e. objects declared 'static', but if you have
1133  * a #GStaticRWLock as a member of a structure, and the structure is
1134  * freed, you should also free the #GStaticRWLock.
1135  *
1136  * Deprecated: 2.32: Use a #GRWLock instead
1137  */
1138 void
1139 g_static_rw_lock_free (GStaticRWLock* lock)
1140 {
1141   g_return_if_fail (lock);
1142
1143   if (lock->read_cond)
1144     {
1145       g_cond_free (lock->read_cond);
1146       lock->read_cond = NULL;
1147     }
1148   if (lock->write_cond)
1149     {
1150       g_cond_free (lock->write_cond);
1151       lock->write_cond = NULL;
1152     }
1153   g_static_mutex_free (&lock->mutex);
1154 }
1155
1156 /* GPrivate {{{1 ------------------------------------------------------ */
1157
1158 /**
1159  * g_private_new:
1160  * @notify: a #GDestroyNotify
1161  *
1162  * Deprecated:2.32: dynamic allocation of #GPrivate is a bad idea.  Use
1163  *                  static storage and G_PRIVATE_INIT() instead.
1164  *
1165  * Returns: a newly allocated #GPrivate (which can never be destroyed)
1166  */
1167 GPrivate *
1168 g_private_new (GDestroyNotify notify)
1169 {
1170   GPrivate tmp = G_PRIVATE_INIT (notify);
1171   GPrivate *key;
1172
1173   key = g_slice_new (GPrivate);
1174   *key = tmp;
1175
1176   return key;
1177 }
1178
1179 /* {{{1 GStaticPrivate */
1180
1181 typedef struct _GStaticPrivateNode GStaticPrivateNode;
1182 struct _GStaticPrivateNode
1183 {
1184   gpointer        data;
1185   GDestroyNotify  destroy;
1186   GStaticPrivate *owner;
1187 };
1188
1189 /**
1190  * GStaticPrivate:
1191  *
1192  * A #GStaticPrivate works almost like a #GPrivate, but it has one
1193  * significant advantage. It doesn't need to be created at run-time
1194  * like a #GPrivate, but can be defined at compile-time. This is
1195  * similar to the difference between #GMutex and #GStaticMutex. Now
1196  * look at our <function>give_me_next_number()</function> example with
1197  * #GStaticPrivate:
1198  *
1199  * <example>
1200  *  <title>Using GStaticPrivate for per-thread data</title>
1201  *  <programlisting>
1202  *   int
1203  *   give_me_next_number (<!-- -->)
1204  *   {
1205  *     static GStaticPrivate current_number_key = G_STATIC_PRIVATE_INIT;
1206  *     int *current_number = g_static_private_get (&amp;current_number_key);
1207  *
1208  *     if (!current_number)
1209  *       {
1210  *         current_number = g_new (int,1);
1211  *         *current_number = 0;
1212  *         g_static_private_set (&amp;current_number_key, current_number, g_free);
1213  *       }
1214  *
1215  *     *current_number = calc_next_number (*current_number);
1216  *
1217  *     return *current_number;
1218  *   }
1219  *  </programlisting>
1220  * </example>
1221  */
1222
1223 /**
1224  * G_STATIC_PRIVATE_INIT:
1225  *
1226  * Every #GStaticPrivate must be initialized with this macro, before it
1227  * can be used.
1228  *
1229  * |[
1230  *   GStaticPrivate my_private = G_STATIC_PRIVATE_INIT;
1231  * ]|
1232  */
1233
1234 /**
1235  * g_static_private_init:
1236  * @private_key: a #GStaticPrivate to be initialized
1237  *
1238  * Initializes @private_key. Alternatively you can initialize it with
1239  * #G_STATIC_PRIVATE_INIT.
1240  */
1241 void
1242 g_static_private_init (GStaticPrivate *private_key)
1243 {
1244   private_key->index = 0;
1245 }
1246
1247 /**
1248  * g_static_private_get:
1249  * @private_key: a #GStaticPrivate
1250  *
1251  * Works like g_private_get() only for a #GStaticPrivate.
1252  *
1253  * This function works even if g_thread_init() has not yet been called.
1254  *
1255  * Returns: the corresponding pointer
1256  */
1257 gpointer
1258 g_static_private_get (GStaticPrivate *private_key)
1259 {
1260   GRealThread *self = (GRealThread*) g_thread_self ();
1261   GArray *array;
1262   gpointer ret = NULL;
1263   array = self->private_data;
1264
1265   if (array && private_key->index != 0 && private_key->index <= array->len)
1266     {
1267       GStaticPrivateNode *node;
1268
1269       node = &g_array_index (array, GStaticPrivateNode, private_key->index - 1);
1270
1271       /* Deal with the possibility that the GStaticPrivate which used
1272        * to have this index got freed and the index got allocated to
1273        * a new one. In this case, the data in the node is stale, so
1274        * free it and return NULL.
1275        */
1276       if (G_UNLIKELY (node->owner != private_key))
1277         {
1278           if (node->destroy)
1279             node->destroy (node->data);
1280           node->destroy = NULL;
1281           node->data = NULL;
1282           node->owner = NULL;
1283         }
1284       ret = node->data;
1285     }
1286
1287   return ret;
1288 }
1289
1290 /**
1291  * g_static_private_set:
1292  * @private_key: a #GStaticPrivate
1293  * @data: the new pointer
1294  * @notify: a function to be called with the pointer whenever the
1295  *     current thread ends or sets this pointer again
1296  *
1297  * Sets the pointer keyed to @private_key for the current thread and
1298  * the function @notify to be called with that pointer (%NULL or
1299  * non-%NULL), whenever the pointer is set again or whenever the
1300  * current thread ends.
1301  *
1302  * This function works even if g_thread_init() has not yet been called.
1303  * If g_thread_init() is called later, the @data keyed to @private_key
1304  * will be inherited only by the main thread, i.e. the one that called
1305  * g_thread_init().
1306  *
1307  * <note><para>@notify is used quite differently from @destructor in
1308  * g_private_new().</para></note>
1309  */
1310 void
1311 g_static_private_set (GStaticPrivate *private_key,
1312                       gpointer        data,
1313                       GDestroyNotify  notify)
1314 {
1315   GRealThread *self = (GRealThread*) g_thread_self ();
1316   GArray *array;
1317   static guint next_index = 0;
1318   GStaticPrivateNode *node;
1319
1320   if (!private_key->index)
1321     {
1322       G_LOCK (g_thread);
1323
1324       if (!private_key->index)
1325         {
1326           if (g_thread_free_indices)
1327             {
1328               private_key->index = GPOINTER_TO_UINT (g_thread_free_indices->data);
1329               g_thread_free_indices = g_slist_delete_link (g_thread_free_indices,
1330                                                            g_thread_free_indices);
1331             }
1332           else
1333             private_key->index = ++next_index;
1334         }
1335
1336       G_UNLOCK (g_thread);
1337     }
1338
1339   array = self->private_data;
1340   if (!array)
1341     {
1342       array = g_array_new (FALSE, TRUE, sizeof (GStaticPrivateNode));
1343       self->private_data = array;
1344     }
1345   if (private_key->index > array->len)
1346     g_array_set_size (array, private_key->index);
1347
1348   node = &g_array_index (array, GStaticPrivateNode, private_key->index - 1);
1349
1350   if (node->destroy)
1351     node->destroy (node->data);
1352
1353   node->data = data;
1354   node->destroy = notify;
1355   node->owner = private_key;
1356 }
1357
1358 /**
1359  * g_static_private_free:
1360  * @private_key: a #GStaticPrivate to be freed
1361  *
1362  * Releases all resources allocated to @private_key.
1363  *
1364  * You don't have to call this functions for a #GStaticPrivate with an
1365  * unbounded lifetime, i.e. objects declared 'static', but if you have
1366  * a #GStaticPrivate as a member of a structure and the structure is
1367  * freed, you should also free the #GStaticPrivate.
1368  */
1369 void
1370 g_static_private_free (GStaticPrivate *private_key)
1371 {
1372   guint idx = private_key->index;
1373
1374   if (!idx)
1375     return;
1376
1377   private_key->index = 0;
1378
1379   /* Freeing the per-thread data is deferred to either the
1380    * thread end or the next g_static_private_get() call for
1381    * the same index.
1382    */
1383   G_LOCK (g_thread);
1384   g_thread_free_indices = g_slist_prepend (g_thread_free_indices,
1385                                            GUINT_TO_POINTER (idx));
1386   G_UNLOCK (g_thread);
1387 }
1388
1389 void
1390 g_static_private_cleanup (GRealThread *thread)
1391 {
1392   GArray *array;
1393
1394   array = thread->private_data;
1395   thread->private_data = NULL;
1396
1397   if (array)
1398     {
1399       guint i;
1400
1401       for (i = 0; i < array->len; i++ )
1402         {
1403           GStaticPrivateNode *node = &g_array_index (array, GStaticPrivateNode, i);
1404           if (node->destroy)
1405             node->destroy (node->data);
1406         }
1407       g_array_free (array, TRUE);
1408     }
1409 }
1410
1411 /* GMutex {{{1 ------------------------------------------------------ */
1412
1413 /**
1414  * g_mutex_new:
1415  *
1416  * Allocates and initializes a new #GMutex.
1417  *
1418  * Returns: a newly allocated #GMutex. Use g_mutex_free() to free
1419  *
1420  * Deprecated:3.32:GMutex can now be statically allocated, or embedded
1421  * in structures and initialised with g_mutex_init().
1422  */
1423 GMutex *
1424 g_mutex_new (void)
1425 {
1426   GMutex *mutex;
1427
1428   mutex = g_slice_new (GMutex);
1429   g_mutex_init (mutex);
1430
1431   return mutex;
1432 }
1433
1434 /**
1435  * g_mutex_free:
1436  * @mutex: a #GMutex
1437  *
1438  * Destroys a @mutex that has been created with g_mutex_new().
1439  *
1440  * Calling g_mutex_free() on a locked mutex may result
1441  * in undefined behaviour.
1442  *
1443  * Deprecated:3.32:GMutex can now be statically allocated, or embedded
1444  * in structures and initialised with g_mutex_init().
1445  */
1446 void
1447 g_mutex_free (GMutex *mutex)
1448 {
1449   g_mutex_clear (mutex);
1450   g_slice_free (GMutex, mutex);
1451 }
1452
1453 /* GCond {{{1 ------------------------------------------------------ */
1454
1455 /**
1456  * g_cond_new:
1457  *
1458  * Allocates and initializes a new #GCond.
1459  *
1460  * Returns: a newly allocated #GCond. Free with g_cond_free()
1461  *
1462  * Deprecated:3.32:GCond can now be statically allocated, or embedded
1463  * in structures and initialised with g_cond_init().
1464  */
1465 GCond *
1466 g_cond_new (void)
1467 {
1468   GCond *cond;
1469
1470   cond = g_slice_new (GCond);
1471   g_cond_init (cond);
1472
1473   return cond;
1474 }
1475
1476 /**
1477  * g_cond_free:
1478  * @cond: a #GCond
1479  *
1480  * Destroys a #GCond that has been created with g_cond_new().
1481  *
1482  * Calling g_cond_free() for a #GCond on which threads are
1483  * blocking leads to undefined behaviour.
1484  *
1485  * Deprecated:3.32:GCond can now be statically allocated, or embedded
1486  * in structures and initialised with g_cond_init().
1487  */
1488 void
1489 g_cond_free (GCond *cond)
1490 {
1491   g_cond_clear (cond);
1492   g_slice_free (GCond, cond);
1493 }
1494
1495 /* {{{1 Epilogue */
1496 /* vim: set foldmethod=marker: */