diff options
author | Ray Strode <rstrode@redhat.com> | 2022-05-16 13:59:44 -0400 |
---|---|---|
committer | Ray Strode <rstrode@redhat.com> | 2023-04-12 14:09:20 -0400 |
commit | 2249e961fbd05f56cf37281309497ec8cba2b7be (patch) | |
tree | 2c3284f6e7b90fa7b4879ea03ca023c9f6274b3e | |
parent | 15bd34f4d36fbd046d7965c4828dbe247e5cad17 (diff) | |
download | glib-2249e961fbd05f56cf37281309497ec8cba2b7be.tar.gz |
gmetrics: Run metrics timeouts on dedicated threadhalfline/debug-metrics
Some of the timeout handlers can take seconds to complete, so
run them from their own thread instead of the main thread.
-rw-r--r-- | glib/gmain.c | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/glib/gmain.c b/glib/gmain.c index fb51bab16..1f326f110 100644 --- a/glib/gmain.c +++ b/glib/gmain.c @@ -447,6 +447,7 @@ static gboolean g_idle_dispatch (GSource *source, static void block_source (GSource *source); static GMainContext *glib_worker_context; +static GMainContext *glib_metrics_context; G_LOCK_DEFINE_STATIC (main_loop); static GMainContext *default_main_context; @@ -925,6 +926,15 @@ on_timeout_fd_ready (void) return G_SOURCE_CONTINUE; } +static gpointer +glib_metrics_main (gpointer data) +{ + while (TRUE) + g_main_context_iteration (glib_metrics_context, TRUE); + + return NULL; +} + /** * g_main_context_new: * @@ -1059,7 +1069,15 @@ g_main_context_new (void) if (metrics_timeout_source != NULL) { - g_source_attach (metrics_timeout_source, context); + sigset_t prev_mask; + sigset_t all; + + sigfillset (&all); + pthread_sigmask (SIG_SETMASK, &all, &prev_mask); + glib_metrics_context = g_main_context_new (); + g_thread_new ("gmetrics", glib_metrics_main, NULL); + pthread_sigmask (SIG_SETMASK, &prev_mask, NULL); + g_source_attach (metrics_timeout_source, glib_metrics_context); g_source_unref (metrics_timeout_source); } |