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