[glib/wip/jtojnar/gsrc-dstr-example] Modernize g_source_is_destroyed example
- From: Jan Tojnar <jtojnar src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib/wip/jtojnar/gsrc-dstr-example] Modernize g_source_is_destroyed example
- Date: Mon, 4 Jan 2021 13:28:18 +0000 (UTC)
commit 71b3deb901d1a0eb427317bf380ff4ae3332bf6d
Author: Jan Tojnar <jtojnar gmail com>
Date: Mon Jan 4 14:19:22 2021 +0100
Modernize g_source_is_destroyed example
gtk_threads_{leave,enter} API is deprecated and a narrower critical section,
guarding just idle_id manipulation, is better anyway.
Fixes: https://gitlab.gnome.org/GNOME/glib/-/issues/2279
glib/gmain.c | 20 ++++++++++++++++----
1 file changed, 16 insertions(+), 4 deletions(-)
---
diff --git a/glib/gmain.c b/glib/gmain.c
index 88140c865..b350de60f 100644
--- a/glib/gmain.c
+++ b/glib/gmain.c
@@ -3116,10 +3116,10 @@ g_main_current_source (void)
* {
* SomeWidget *self = data;
*
- * GDK_THREADS_ENTER ();
+ * g_mutex_lock (&self->idle_id_mutex);
* // do stuff with self
* self->idle_id = 0;
- * GDK_THREADS_LEAVE ();
+ * g_mutex_unlock (&self->idle_id_mutex);
*
* return G_SOURCE_REMOVE;
* }
@@ -3127,9 +3127,19 @@ g_main_current_source (void)
* static void
* some_widget_do_stuff_later (SomeWidget *self)
* {
+ * g_mutex_lock (&self->idle_id_mutex);
* self->idle_id = g_idle_add (idle_callback, self);
+ * g_mutex_unlock (&self->idle_id_mutex);
* }
*
+ * static void
+ * some_widget_init (SomeWidget *self)
+ * {
+ * g_mutex_init (&self->idle_id_mutex);
+ *
+ * // ...
+ * }
+ *
* static void
* some_widget_finalize (GObject *object)
* {
@@ -3138,6 +3148,8 @@ g_main_current_source (void)
* if (self->idle_id)
* g_source_remove (self->idle_id);
*
+ * g_mutex_clear (&self->idle_id_mutex);
+ *
* G_OBJECT_CLASS (parent_class)->finalize (object);
* }
* ]|
@@ -3154,12 +3166,12 @@ g_main_current_source (void)
* {
* SomeWidget *self = data;
*
- * GDK_THREADS_ENTER ();
+ * g_mutex_lock (&self->idle_id_mutex);
* if (!g_source_is_destroyed (g_main_current_source ()))
* {
* // do stuff with self
* }
- * GDK_THREADS_LEAVE ();
+ * g_mutex_unlock (&self->idle_id_mutex);
*
* return FALSE;
* }
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]