Merge remote-tracking branch 'origin/master' into 0.11
[platform/upstream/gstreamer.git] / 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
8 #ifndef __GLIB_COMPAT_PRIVATE_H__
9 #define __GLIB_COMPAT_PRIVATE_H__
10
11 #include <glib.h>
12
13 G_BEGIN_DECLS
14
15 #if !GLIB_CHECK_VERSION(2,25,0)
16
17 #if defined (_MSC_VER) && !defined(_WIN64)
18 typedef struct _stat32 GStatBuf;
19 #else
20 typedef struct stat GStatBuf;
21 #endif
22
23 #endif
24
25 #if GLIB_CHECK_VERSION(2,26,0)
26 #define GLIB_HAS_GDATETIME
27 #endif
28
29 /* See bug #651514 */
30 #if GLIB_CHECK_VERSION(2,29,5)
31 #define G_ATOMIC_POINTER_COMPARE_AND_EXCHANGE(a,b,c) \
32     g_atomic_pointer_compare_and_exchange ((a),(b),(c))
33 #define G_ATOMIC_INT_COMPARE_AND_EXCHANGE(a,b,c) \
34     g_atomic_int_compare_and_exchange ((a),(b),(c))
35 #else
36 #define G_ATOMIC_POINTER_COMPARE_AND_EXCHANGE(a,b,c) \
37     g_atomic_pointer_compare_and_exchange ((volatile gpointer *)(a),(b),(c))
38 #define G_ATOMIC_INT_COMPARE_AND_EXCHANGE(a,b,c) \
39     g_atomic_int_compare_and_exchange ((volatile int *)(a),(b),(c))
40 #endif
41
42 /* See bug #651514 */
43 #if GLIB_CHECK_VERSION(2,29,5)
44 #define G_ATOMIC_INT_ADD(a,b) g_atomic_int_add ((a),(b))
45 #else
46 #define G_ATOMIC_INT_ADD(a,b) g_atomic_int_exchange_and_add ((a),(b))
47 #endif
48
49 /* copies */
50
51 #if GLIB_CHECK_VERSION (2, 31, 0)
52 #define g_mutex_new gst_g_mutex_new
53 static inline GMutex *
54 gst_g_mutex_new (void)
55 {
56   GMutex *mutex = g_slice_new (GMutex);
57   g_mutex_init (mutex);
58   return mutex;
59 }
60 #define g_mutex_free gst_g_mutex_free
61 static inline void
62 gst_g_mutex_free (GMutex *mutex)
63 {
64   g_mutex_clear (mutex);
65   g_slice_free (GMutex, mutex);
66 }
67 #define g_static_rec_mutex_init gst_g_static_rec_mutex_init
68 static inline void
69 gst_g_static_rec_mutex_init (GStaticRecMutex *mutex)
70 {
71   static const GStaticRecMutex init_mutex = G_STATIC_REC_MUTEX_INIT;
72
73   *mutex = init_mutex;
74 }
75 #define g_cond_new gst_g_cond_new
76 static inline GCond *
77 gst_g_cond_new (void)
78 {
79   GCond *cond = g_slice_new (GCond);
80   g_cond_init (cond);
81   return cond;
82 }
83 #define g_cond_free gst_g_cond_free
84 static inline void
85 gst_g_cond_free (GCond *cond)
86 {
87   g_cond_clear (cond);
88   g_slice_free (GCond, cond);
89 }
90 #define g_cond_timed_wait gst_g_cond_timed_wait
91 static inline gboolean
92 gst_g_cond_timed_wait (GCond *cond, GMutex *mutex, GTimeVal *abs_time)
93 {
94   gint64 end_time;
95
96   if (abs_time == NULL) {
97     g_cond_wait (cond, mutex);
98     return TRUE;
99   }
100
101   end_time = abs_time->tv_sec;
102   end_time *= 1000000;
103   end_time += abs_time->tv_usec;
104
105   /* would be nice if we had clock_rtoffset, but that didn't seem to
106    * make it into the kernel yet...
107    */
108   /* if CLOCK_MONOTONIC is not defined then g_get_montonic_time() and
109    * g_get_real_time() are returning the same clock and we'd add ~0
110    */
111   end_time += g_get_monotonic_time () - g_get_real_time ();
112   return g_cond_wait_until (cond, mutex, end_time);
113 }
114 #endif /* GLIB_CHECK_VERSION (2, 31, 0) */
115
116 /* adaptations */
117
118 G_END_DECLS
119
120 #endif