[libvirt-glib 2/9] Register event using GOnce to avoid multiple initializations

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



---
 libvirt-glib/libvirt-glib-event.c |   11 ++++++++++-
 1 files changed, 10 insertions(+), 1 deletions(-)

diff --git a/libvirt-glib/libvirt-glib-event.c b/libvirt-glib/libvirt-glib-event.c
index 65af739..a785c93 100644
--- a/libvirt-glib/libvirt-glib-event.c
+++ b/libvirt-glib/libvirt-glib-event.c
@@ -359,7 +359,8 @@ cleanup:
 }
 
 
-void gvir_event_register(void) {
+static gpointer event_register_once(gpointer data G_GNUC_UNUSED)
+{
     eventlock = g_mutex_new();
     virEventRegisterImpl(gvir_event_handle_add,
                          gvir_event_handle_update,
@@ -367,5 +368,13 @@ void gvir_event_register(void) {
                          gvir_event_timeout_add,
                          gvir_event_timeout_update,
                          gvir_event_timeout_remove);
+    return NULL;
+}
+
+void gvir_event_register(void)
+{
+    static GOnce once = G_ONCE_INIT;
+
+    g_once(&once, event_register_once, NULL);
 }
 
-- 
1.7.6.2

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list


[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]