Use new GLib API unconditionally
[platform/upstream/gst-plugins-good.git] / gst-libs / gst / glib-compat-private.h
1 /*
2  * glib-compat.c
3  * Functions copied from glib 2.10
4  *
5  * Copyright 2005 David Schleef <ds@schleef.org>
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Library General Public
9  * License as published by the Free Software Foundation; either
10  * version 2 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * Library General Public License for more details.
16  *
17  * You should have received a copy of the GNU Library General Public
18  * License along with this library; if not, write to the
19  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20  * Boston, MA 02111-1307, USA.
21  */
22
23 #ifndef __GLIB_COMPAT_PRIVATE_H__
24 #define __GLIB_COMPAT_PRIVATE_H__
25
26 #include <glib.h>
27
28 G_BEGIN_DECLS
29
30 #if GLIB_CHECK_VERSION(2,26,0)
31 #define GLIB_HAS_GDATETIME
32 #endif
33
34 /* copies */
35
36 #if 0 //GLIB_CHECK_VERSION (2, 31, 0)
37 #define g_mutex_new gst_g_mutex_new
38 static inline GMutex *
39 gst_g_mutex_new (void)
40 {
41   GMutex *mutex = g_slice_new (GMutex);
42   g_mutex_init (mutex);
43   return mutex;
44 }
45 #define g_mutex_free gst_g_mutex_free
46 static inline void
47 gst_g_mutex_free (GMutex *mutex)
48 {
49   g_mutex_clear (mutex);
50   g_slice_free (GMutex, mutex);
51 }
52 #define g_static_rec_mutex_init gst_g_static_rec_mutex_init
53 static inline void
54 gst_g_static_rec_mutex_init (GStaticRecMutex *mutex)
55 {
56   static const GStaticRecMutex init_mutex = G_STATIC_REC_MUTEX_INIT;
57
58   *mutex = init_mutex;
59 }
60 #define g_cond_new gst_g_cond_new
61 static inline GCond *
62 gst_g_cond_new (void)
63 {
64   GCond *cond = g_slice_new (GCond);
65   g_cond_init (cond);
66   return cond;
67 }
68 #define g_cond_free gst_g_cond_free
69 static inline void
70 gst_g_cond_free (GCond *cond)
71 {
72   g_cond_clear (cond);
73   g_slice_free (GCond, cond);
74 }
75 #define g_cond_timed_wait gst_g_cond_timed_wait
76 static inline gboolean
77 gst_g_cond_timed_wait (GCond *cond, GMutex *mutex, GTimeVal *abs_time)
78 {
79   gint64 end_time;
80
81   if (abs_time == NULL) {
82     g_cond_wait (cond, mutex);
83     return TRUE;
84   }
85
86   end_time = abs_time->tv_sec;
87   end_time *= 1000000;
88   end_time += abs_time->tv_usec;
89
90   /* would be nice if we had clock_rtoffset, but that didn't seem to
91    * make it into the kernel yet...
92    */
93   /* if CLOCK_MONOTONIC is not defined then g_get_montonic_time() and
94    * g_get_real_time() are returning the same clock and we'd add ~0
95    */
96   end_time += g_get_monotonic_time () - g_get_real_time ();
97   return g_cond_wait_until (cond, mutex, end_time);
98 }
99 #endif /* GLIB_CHECK_VERSION (2, 31, 0) */
100
101 /* adaptations */
102
103 G_END_DECLS
104
105 #endif