diff options
author | Ray Strode <rstrode@redhat.com> | 2022-05-16 13:59:44 -0400 |
---|---|---|
committer | Ray Strode <rstrode@redhat.com> | 2023-04-18 14:08:47 -0400 |
commit | 24506bed1ff32ec266216a99211bdfd7afebebe8 (patch) | |
tree | 5bfcc1c05024b08671bebebe57ccf77a9198b20c | |
parent | e10fe825b44ef2ed17c3b80c0aa26b9f53d59036 (diff) | |
download | glib-halfline/debug-metrics-2.76.tar.gz |
gmetrics: Run metrics timeouts on dedicated threadhalfline/debug-metrics-2.76
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 234e84ffd..107925f87 100644 --- a/glib/gmain.c +++ b/glib/gmain.c @@ -494,6 +494,7 @@ static gboolean g_idle_dispatch (GSource *source, static void block_source (GSource *source); static GMainContext *glib_worker_context; +static GMainContext *glib_metrics_context; #ifndef G_OS_WIN32 @@ -1019,6 +1020,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: * @@ -1171,7 +1181,15 @@ g_main_context_new_with_flags (GMainContextFlags flags) 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); } |