Tizen 2.1 base
[framework/multimedia/gstreamer-vaapi.git] / gst-libs / gst / vaapi / glibcompat.h
1 /*
2  *  glibcompat.h - System-dependent definitions
3  *
4  *  Copyright (C) 2012 Intel Corporation
5  *
6  *  This library is free software; you can redistribute it and/or
7  *  modify it under the terms of the GNU Lesser General Public License
8  *  as published by the Free Software Foundation; either version 2.1
9  *  of the License, or (at your option) any later version.
10  *
11  *  This library is distributed in the hope that it will be useful,
12  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  *  Lesser General Public License for more details.
15  *
16  *  You should have received a copy of the GNU Lesser General Public
17  *  License along with this library; if not, write to the Free
18  *  Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19  *  Boston, MA 02110-1301 USA
20  */
21
22 #ifndef GLIB_COMPAT_H
23 #define GLIB_COMPAT_H
24
25 #include <glib.h>
26 #include <glib-object.h>
27
28 #if !GLIB_CHECK_VERSION(2,27,2)
29 static inline void
30 g_list_free_full(GList *list, GDestroyNotify free_func)
31 {
32     g_list_foreach(list, (GFunc)free_func, NULL);
33     g_list_free(list);
34 }
35 #endif
36
37 #if !GLIB_CHECK_VERSION(2,28,0)
38 static inline void
39 g_clear_object_inline(volatile GObject **object_ptr)
40 {
41     gpointer * const ptr = (gpointer)object_ptr;
42     gpointer old;
43
44     do {
45         old = g_atomic_pointer_get(ptr);
46     } while G_UNLIKELY(!g_atomic_pointer_compare_and_exchange(ptr, old, NULL));
47
48     if (old)
49         g_object_unref(old);
50 }
51 #undef  g_clear_object
52 #define g_clear_object(obj) g_clear_object_inline((volatile GObject **)(obj))
53 #endif
54
55 #if GLIB_CHECK_VERSION(2,31,2)
56 #define GStaticMutex                    GMutex
57 #undef  g_static_mutex_init
58 #define g_static_mutex_init(mutex)      g_mutex_init(mutex)
59 #undef  g_static_mutex_free
60 #define g_static_mutex_free(mutex)      g_mutex_clear(mutex)
61 #undef  g_static_mutex_lock
62 #define g_static_mutex_lock(mutex)      g_mutex_lock(mutex)
63 #undef  g_static_mutex_unlock
64 #define g_static_mutex_unlock(mutex)    g_mutex_unlock(mutex)
65
66 #define GStaticRecMutex                 GRecMutex
67 #undef  g_static_rec_mutex_init
68 #define g_static_rec_mutex_init(mutex)  g_rec_mutex_init(mutex)
69 #undef  g_static_rec_mutex_free
70 #define g_static_rec_mutex_free(mutex)  g_rec_mutex_clear(mutex)
71 #undef  g_static_rec_mutex_lock
72 #define g_static_rec_mutex_lock(mutex)  g_rec_mutex_lock(mutex)
73 #undef  g_static_rec_mutex_unlock
74 #define g_static_rec_mutex_unlock(m)    g_rec_mutex_unlock(m)
75 #endif
76
77 #endif /* GLIB_COMPAT_H */