Commit 720dfa8c authored by Jan Tojnar's avatar Jan Tojnar Committed by Philip Withnall
Browse files

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: #2279
parent 87e8eb67
Pipeline #243840 passed with stages
in 24 minutes and 39 seconds
......@@ -3125,10 +3125,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;
* }
......@@ -3136,9 +3136,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)
* {
......@@ -3147,6 +3157,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);
* }
* ]|
......@@ -3163,12 +3175,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;
* }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment