[libvirt PATCH 1/2] util: Move glib event loop workaround to glibcompat

Martin Kletzander posted 2 patches 4 years, 11 months ago
[libvirt PATCH 1/2] util: Move glib event loop workaround to glibcompat
Posted by Martin Kletzander 4 years, 11 months ago
This way it can be used from other places as well.

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
---
 src/util/glibcompat.c   | 35 +++++++++++++++++++++++++++++++++++
 src/util/glibcompat.h   | 11 +++++++++++
 src/util/vireventglib.c | 30 ------------------------------
 3 files changed, 46 insertions(+), 30 deletions(-)

diff --git a/src/util/glibcompat.c b/src/util/glibcompat.c
index 9f0f7f015cad..76fda18a62d8 100644
--- a/src/util/glibcompat.c
+++ b/src/util/glibcompat.c
@@ -211,3 +211,38 @@ 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)
+# 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)
+{
+    GSource *src = data;
+
+    g_source_unref(src);
+
+    return FALSE;
+}
+#endif
diff --git a/src/util/glibcompat.h b/src/util/glibcompat.h
index 6463c4179a7e..9c528432742b 100644
--- a/src/util/glibcompat.h
+++ b/src/util/glibcompat.h
@@ -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
diff --git a/src/util/vireventglib.c b/src/util/vireventglib.c
index 193b3bfde240..88e3ec6d5dbb 100644
--- a/src/util/vireventglib.c
+++ b/src/util/vireventglib.c
@@ -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,
-- 
2.30.1

Re: [libvirt PATCH 1/2] util: Move glib event loop workaround to glibcompat
Posted by Daniel P. Berrangé 4 years, 11 months ago
On Thu, Mar 04, 2021 at 10:48:10AM +0100, Martin Kletzander wrote:
> This way it can be used from other places as well.
> 
> Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
> ---
>  src/util/glibcompat.c   | 35 +++++++++++++++++++++++++++++++++++
>  src/util/glibcompat.h   | 11 +++++++++++
>  src/util/vireventglib.c | 30 ------------------------------
>  3 files changed, 46 insertions(+), 30 deletions(-)

9rev


Regards,
Daniel
-- 
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|

Re: [libvirt PATCH 1/2] util: Move glib event loop workaround to glibcompat
Posted by Daniel P. Berrangé 4 years, 11 months ago
On Thu, Mar 04, 2021 at 10:20:14AM +0000, Daniel P. Berrangé wrote:
> On Thu, Mar 04, 2021 at 10:48:10AM +0100, Martin Kletzander wrote:
> > This way it can be used from other places as well.
> > 
> > Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
> > ---
> >  src/util/glibcompat.c   | 35 +++++++++++++++++++++++++++++++++++
> >  src/util/glibcompat.h   | 11 +++++++++++
> >  src/util/vireventglib.c | 30 ------------------------------
> >  3 files changed, 46 insertions(+), 30 deletions(-)
> 
> 9rev

which should be

Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>

Regards,
Daniel
-- 
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|