tizen 2.3 release
[framework/multimedia/gst-plugins-base0.10.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,25,0)
31
32 #if defined (_MSC_VER) && !defined(_WIN64)
33 typedef struct _stat32 GStatBuf;
34 #else
35 typedef struct stat GStatBuf;
36 #endif
37
38 #endif
39
40 #if GLIB_CHECK_VERSION(2,26,0)
41 #define GLIB_HAS_GDATETIME
42 #endif
43
44 /* See bug #651514 */
45 #if GLIB_CHECK_VERSION(2,29,5)
46 #define G_ATOMIC_POINTER_COMPARE_AND_EXCHANGE(a,b,c) \
47     g_atomic_pointer_compare_and_exchange ((a),(b),(c))
48 #define G_ATOMIC_INT_COMPARE_AND_EXCHANGE(a,b,c) \
49     g_atomic_int_compare_and_exchange ((a),(b),(c))
50 #else
51 #define G_ATOMIC_POINTER_COMPARE_AND_EXCHANGE(a,b,c) \
52     g_atomic_pointer_compare_and_exchange ((volatile gpointer *)(a),(b),(c))
53 #define G_ATOMIC_INT_COMPARE_AND_EXCHANGE(a,b,c) \
54     g_atomic_int_compare_and_exchange ((volatile int *)(a),(b),(c))
55 #endif
56
57 /* See bug #651514 */
58 #if GLIB_CHECK_VERSION(2,29,5)
59 #define G_ATOMIC_INT_ADD(a,b) g_atomic_int_add ((a),(b))
60 #else
61 #define G_ATOMIC_INT_ADD(a,b) g_atomic_int_exchange_and_add ((a),(b))
62 #endif
63
64 /* copies */
65
66 #if GLIB_CHECK_VERSION (2, 31, 0)
67 #define g_mutex_new gst_g_mutex_new
68 static inline GMutex *
69 gst_g_mutex_new (void)
70 {
71   GMutex *mutex = g_slice_new (GMutex);
72   g_mutex_init (mutex);
73   return mutex;
74 }
75 #define g_mutex_free gst_g_mutex_free
76 static inline void
77 gst_g_mutex_free (GMutex *mutex)
78 {
79   g_mutex_clear (mutex);
80   g_slice_free (GMutex, mutex);
81 }
82 #define g_static_rec_mutex_init gst_g_static_rec_mutex_init
83 static inline void
84 gst_g_static_rec_mutex_init (GStaticRecMutex *mutex)
85 {
86   static const GStaticRecMutex init_mutex = G_STATIC_REC_MUTEX_INIT;
87
88   *mutex = init_mutex;
89 }
90 #define g_cond_new gst_g_cond_new
91 static inline GCond *
92 gst_g_cond_new (void)
93 {
94   GCond *cond = g_slice_new (GCond);
95   g_cond_init (cond);
96   return cond;
97 }
98 #define g_cond_free gst_g_cond_free
99 static inline void
100 gst_g_cond_free (GCond *cond)
101 {
102   g_cond_clear (cond);
103   g_slice_free (GCond, cond);
104 }
105 #define g_cond_timed_wait gst_g_cond_timed_wait
106 static inline gboolean
107 gst_g_cond_timed_wait (GCond *cond, GMutex *mutex, GTimeVal *abs_time)
108 {
109   gint64 end_time;
110
111   if (abs_time == NULL) {
112     g_cond_wait (cond, mutex);
113     return TRUE;
114   }
115
116   end_time = abs_time->tv_sec;
117   end_time *= 1000000;
118   end_time += abs_time->tv_usec;
119
120   /* would be nice if we had clock_rtoffset, but that didn't seem to
121    * make it into the kernel yet...
122    */
123   /* if CLOCK_MONOTONIC is not defined then g_get_montonic_time() and
124    * g_get_real_time() are returning the same clock and we'd add ~0
125    */
126   end_time += g_get_monotonic_time () - g_get_real_time ();
127   return g_cond_wait_until (cond, mutex, end_time);
128 }
129 #endif /* GLIB_CHECK_VERSION (2, 31, 0) */
130
131 /* adaptations */
132
133 G_END_DECLS
134
135 #endif