xref: /openbmc/qemu/include/glib-compat.h (revision 8f1e884b)
1 /*
2  * GLIB Compatibility Functions
3  *
4  * Copyright IBM, Corp. 2013
5  *
6  * Authors:
7  *  Anthony Liguori   <aliguori@us.ibm.com>
8  *
9  * This work is licensed under the terms of the GNU GPL, version 2 or later.
10  * See the COPYING file in the top-level directory.
11  *
12  */
13 
14 #ifndef QEMU_GLIB_COMPAT_H
15 #define QEMU_GLIB_COMPAT_H
16 
17 #include <glib.h>
18 
19 #if !GLIB_CHECK_VERSION(2, 14, 0)
20 static inline guint g_timeout_add_seconds(guint interval, GSourceFunc function,
21                                           gpointer data)
22 {
23     return g_timeout_add(interval * 1000, function, data);
24 }
25 #endif
26 
27 #ifdef _WIN32
28 /*
29  * g_poll has a problem on Windows when using
30  * timeouts < 10ms, so use wrapper.
31  */
32 #define g_poll(fds, nfds, timeout) g_poll_fixed(fds, nfds, timeout)
33 gint g_poll_fixed(GPollFD *fds, guint nfds, gint timeout);
34 #elif !GLIB_CHECK_VERSION(2, 20, 0)
35 /*
36  * Glib before 2.20.0 doesn't implement g_poll, so wrap it to compile properly
37  * on older systems.
38  */
39 static inline gint g_poll(GPollFD *fds, guint nfds, gint timeout)
40 {
41     GMainContext *ctx = g_main_context_default();
42     return g_main_context_get_poll_func(ctx)(fds, nfds, timeout);
43 }
44 #endif
45 
46 #endif
47