summaryrefslogtreecommitdiff
path: root/gst-libs/gst/vaapi/glibcompat.h
blob: 0a6115c913098fde18773df56279f9a3847112a0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
/*
 *  glibcompat.h - System-dependent definitions
 *
 *  Copyright (C) 2012 Intel Corporation
 *
 *  This library is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Lesser General Public License
 *  as published by the Free Software Foundation; either version 2.1
 *  of the License, or (at your option) any later version.
 *
 *  This library is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *  Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public
 *  License along with this library; if not, write to the Free
 *  Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 *  Boston, MA 02110-1301 USA
 */

#ifndef GLIB_COMPAT_H
#define GLIB_COMPAT_H

#include <glib.h>
#include <glib-object.h>

#if !GLIB_CHECK_VERSION(2,27,2)
static inline void
g_list_free_full(GList *list, GDestroyNotify free_func)
{
    g_list_foreach(list, (GFunc)free_func, NULL);
    g_list_free(list);
}
#endif

#if !GLIB_CHECK_VERSION(2,28,0)
static inline void
g_clear_object_inline(volatile GObject **object_ptr)
{
    gpointer * const ptr = (gpointer)object_ptr;
    gpointer old;

    do {
        old = g_atomic_pointer_get(ptr);
    } while G_UNLIKELY(!g_atomic_pointer_compare_and_exchange(ptr, old, NULL));

    if (old)
        g_object_unref(old);
}
#undef  g_clear_object
#define g_clear_object(obj) g_clear_object_inline((volatile GObject **)(obj))
#endif

#if GLIB_CHECK_VERSION(2,31,2)
#define GStaticMutex                    GMutex
#undef  g_static_mutex_init
#define g_static_mutex_init(mutex)      g_mutex_init(mutex)
#undef  g_static_mutex_free
#define g_static_mutex_free(mutex)      g_mutex_clear(mutex)
#undef  g_static_mutex_lock
#define g_static_mutex_lock(mutex)      g_mutex_lock(mutex)
#undef  g_static_mutex_unlock
#define g_static_mutex_unlock(mutex)    g_mutex_unlock(mutex)

#define GStaticRecMutex                 GRecMutex
#undef  g_static_rec_mutex_init
#define g_static_rec_mutex_init(mutex)  g_rec_mutex_init(mutex)
#undef  g_static_rec_mutex_free
#define g_static_rec_mutex_free(mutex)  g_rec_mutex_clear(mutex)
#undef  g_static_rec_mutex_lock
#define g_static_rec_mutex_lock(mutex)  g_rec_mutex_lock(mutex)
#undef  g_static_rec_mutex_unlock
#define g_static_rec_mutex_unlock(m)    g_rec_mutex_unlock(m)
#endif

#if !GLIB_CHECK_VERSION(2,31,2)
static inline gboolean
g_cond_wait_until(GCond *cond, GMutex *mutex, gint64 end_time)
{
    gint64 diff_time;
    GTimeVal timeout;

    diff_time = end_time - g_get_monotonic_time();
    g_get_current_time(&timeout);
    g_time_val_add(&timeout, diff_time > 0 ? diff_time : 0);
    return g_cond_timed_wait(cond, mutex, &timeout);
}
#endif

#endif /* GLIB_COMPAT_H */