[virt-tools-list] [virt-viewer v2 02/13] events: register event using GOnce to avoid multiple initializations
Fabiano Fidêncio
fidencio at redhat.com
Wed Jul 22 08:04:29 UTC 2015
Based on commit 8f8d9ce5238dbcbce40aa04ba55b8c55f97c79c0 from
libvirt-glib.
Original author: Marc-André Lureau <marcandre.lureau at redhat.com>
Related to: rhbz#1243228
---
src/virt-viewer-events.c | 12 ++++++++++--
1 file changed, 10 insertions(+), 2 deletions(-)
diff --git a/src/virt-viewer-events.c b/src/virt-viewer-events.c
index b0a84ba..5e438b8 100644
--- a/src/virt-viewer-events.c
+++ b/src/virt-viewer-events.c
@@ -393,8 +393,8 @@ cleanup:
return ret;
}
-
-void virt_viewer_events_register(void) {
+static gpointer event_register_once(gpointer data G_GNUC_UNUSED)
+{
eventlock = g_mutex_new();
virEventRegisterImpl(virt_viewer_events_add_handle,
virt_viewer_events_update_handle,
@@ -402,6 +402,14 @@ void virt_viewer_events_register(void) {
virt_viewer_events_add_timeout,
virt_viewer_events_update_timeout,
virt_viewer_events_remove_timeout);
+
+ return NULL;
+}
+
+void virt_viewer_events_register(void) {
+ static GOnce once = G_ONCE_INIT;
+
+ g_once(&once, event_register_once, NULL);
}
/*
--
2.4.4
More information about the virt-tools-list
mailing list