]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
util: Move glib event loop workaround to glibcompat
authorMartin Kletzander <mkletzan@redhat.com>
Thu, 4 Mar 2021 08:34:19 +0000 (09:34 +0100)
committerMartin Kletzander <mkletzan@redhat.com>
Fri, 5 Mar 2021 09:17:26 +0000 (10:17 +0100)
This way it can be used from other places as well.

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
meson.build
src/libvirt_glib_crash_workaround.syms [new file with mode: 0644]
src/meson.build
src/util/glibcompat.c
src/util/glibcompat.h
src/util/vireventglib.c

index c225df42d45a27d7b758871623ee848939e755a7..e5d5c4e14df8edec78f2a677d27ff96f11b4cf98 100644 (file)
@@ -1046,6 +1046,9 @@ if host_machine.system() == 'windows'
 else
   gio_dep = dependency('gio-unix-2.0', version: '>=' + glib_version)
 endif
+# GLib event loop race workaround in glibcompat.h, remove when minimum required
+# glib is >= 2.64.0
+glib_crash_workaround = glib_dep.version().version_compare('<2.64.0')
 glib_dep = declare_dependency(
   dependencies: [ glib_dep, gobject_dep, gio_dep ],
 )
diff --git a/src/libvirt_glib_crash_workaround.syms b/src/libvirt_glib_crash_workaround.syms
new file mode 100644 (file)
index 0000000..249058b
--- /dev/null
@@ -0,0 +1,11 @@
+#
+# Private symbols specific for pre-2.64.0 GLib workaround
+#
+
+# util/glibcompat.h
+virEventGLibSourceUnrefIdle;
+
+# Let emacs know we want case-insensitive sorting
+# Local Variables:
+# sort-fold-case: t
+# End:
index f13b85b74e5a99fa93dda517338019204f218879..70a5a83eea3eda471a071cb121e33a59c21d0873 100644 (file)
@@ -124,6 +124,12 @@ else
   sym_files += 'libvirt_libssh2.syms'
 endif
 
+if glib_crash_workaround
+  used_sym_files += 'libvirt_glib_crash_workaround.syms'
+else
+  sym_files += 'libvirt_glib_crash_workaround.syms'
+endif
+
 
 # variables filled by subdirectories
 
index 9f0f7f015cad2bbf422672579cd9ea0221c4b044..fe19ffa87b3fe789e5c22db7e6c87fc04ba69347 100644 (file)
@@ -211,3 +211,36 @@ vir_g_strdup_vprintf(const char *msg, va_list args)
         abort();
     return ret;
 }
+
+
+/*
+ * If the last reference to a GSource is released in a non-main
+ * thread we're exposed to a race condition that causes a
+ * crash:
+ *
+ *    https://gitlab.gnome.org/GNOME/glib/-/merge_requests/1358
+ *
+ * Thus we're using an idle func to release our ref...
+ *
+ * ...but this imposes a significant performance penalty on
+ * I/O intensive workloads which are sensitive to the iterations
+ * of the event loop, so avoid the workaround if we know we have
+ * new enough glib.
+ *
+ * The function below is used from a header file definition.
+ *
+ * Drop when min glib >= 2.64.0
+ */
+#if GLIB_CHECK_VERSION(2, 64, 0) != TRUE
+
+gboolean
+virEventGLibSourceUnrefIdle(gpointer data)
+{
+    GSource *src = data;
+
+    g_source_unref(src);
+
+    return FALSE;
+}
+
+#endif
index 6463c4179a7e65134c8c229b076116c58ecb9ec8..9c528432742ba184d2e45a9b175649b2041508df 100644 (file)
@@ -84,3 +84,14 @@ char *vir_g_strdup_vprintf(const char *msg, va_list args)
 #define g_canonicalize_filename vir_g_canonicalize_filename
 #undef g_fsync
 #define g_fsync vir_g_fsync
+
+/* Drop when min glib >= 2.64.0 */
+#if GLIB_CHECK_VERSION(2, 64, 0)
+# define g_vir_source_unref_safe(source) g_source_unref(source)
+#else
+# define g_vir_source_unref_safe(source) g_idle_add(virEventGLibSourceUnrefIdle, source)
+
+gboolean
+virEventGLibSourceUnrefIdle(gpointer data);
+
+#endif
index 193b3bfde24036ef3f7571f5a97fa99190e738a5..88e3ec6d5dbb84225fc0423e498384d451fe5bff 100644 (file)
@@ -185,36 +185,6 @@ virEventGLibHandleFind(int watch)
     return NULL;
 }
 
-/*
- * If the last reference to a GSource is released in a non-main
- * thread we're exposed to a race condition that causes a
- * crash:
- *
- *    https://gitlab.gnome.org/GNOME/glib/-/merge_requests/1358
- *
- * Thus we're using an idle func to release our ref...
- *
- * ...but this imposes a significant performance penalty on
- * I/O intensive workloads which are sensitive to the iterations
- * of the event loop, so avoid the workaround if we know we have
- * new enough glib.
- */
-#if GLIB_CHECK_VERSION(2, 64, 0)
-# define g_vir_source_unref_safe(source) g_source_unref(source)
-#else
-# define g_vir_source_unref_safe(source) g_idle_add(virEventGLibSourceUnrefIdle, source)
-
-static gboolean
-virEventGLibSourceUnrefIdle(gpointer data)
-{
-    GSource *src = data;
-
-    g_source_unref(src);
-
-    return FALSE;
-}
-#endif
-
 
 static void
 virEventGLibHandleUpdate(int watch,