mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2024-12-27 07:56:14 +01:00
Merge branch 'wip/jtojnar/gsrc-dstr-example' into 'master'
Modernize g_source_is_destroyed example Closes #2279 See merge request GNOME/glib!1835
This commit is contained in:
commit
1ae734dd6d
20
glib/gmain.c
20
glib/gmain.c
@ -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;
|
||||
* }
|
||||
|
Loading…
Reference in New Issue
Block a user