[Spice-devel] [PATCH] compatibility patch for event loop
Frediano Ziglio
fziglio at redhat.com
Mon Feb 1 11:36:52 CET 2016
This patch use old code to implement timer events.
The new version use some function from GLib 2.34 however some systems
(like RHEL 6) have former GLib version (RHEL 6 has GLib 2.28 installed)
Signed-off-by: Frediano Ziglio <fziglio at redhat.com>
---
server/event-loop.c | 60 +++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 60 insertions(+)
diff --git a/server/event-loop.c b/server/event-loop.c
index 6e08d78..9d51026 100644
--- a/server/event-loop.c
+++ b/server/event-loop.c
@@ -24,6 +24,8 @@
#include "red-common.h"
+#if GLIB_VERSION_CUR_STABLE >= GLIB_VERSION_2_34 \
+ && GLIB_VERSION_MAX_ALLOWED >= GLIB_VERSION_2_34
struct SpiceTimer {
GSource source;
};
@@ -72,6 +74,64 @@ static void timer_remove(SpiceTimer *timer)
g_source_destroy(&timer->source);
g_source_unref(&timer->source);
}
+#else
+struct SpiceTimer {
+ GMainContext *context;
+ SpiceTimerFunc func;
+ void *opaque;
+ GSource *source;
+};
+
+static SpiceTimer* timer_add(const SpiceCoreInterfaceInternal *iface,
+ SpiceTimerFunc func, void *opaque)
+{
+ SpiceTimer *timer = spice_malloc0(sizeof(SpiceTimer));
+
+ timer->context = iface->main_context;
+ timer->func = func;
+ timer->opaque = opaque;
+
+ return timer;
+}
+
+static gboolean timer_func(gpointer user_data)
+{
+ SpiceTimer *timer = user_data;
+
+ timer->func(timer->opaque);
+ /* timer might be free after func(), don't touch */
+
+ return FALSE;
+}
+
+static void timer_cancel(SpiceTimer *timer)
+{
+ if (timer->source) {
+ g_source_destroy(timer->source);
+ g_source_unref(timer->source);
+ timer->source = NULL;
+ }
+}
+
+static void timer_start(SpiceTimer *timer, uint32_t ms)
+{
+ timer_cancel(timer);
+
+ timer->source = g_timeout_source_new(ms);
+ spice_assert(timer->source != NULL);
+
+ g_source_set_callback(timer->source, timer_func, timer, NULL);
+
+ g_source_attach(timer->source, timer->context);
+}
+
+static void timer_remove(SpiceTimer *timer)
+{
+ timer_cancel(timer);
+ spice_assert(timer->source == NULL);
+ free(timer);
+}
+#endif
struct SpiceWatch {
GMainContext *context;
--
2.4.3
More information about the Spice-devel
mailing list