summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhilip Withnall <withnall@endlessm.com>2020-09-02 11:53:37 +0100
committerPhilip Withnall <withnall@endlessm.com>2020-09-02 16:09:12 +0100
commitc8840ff9a8f8445e81ded935bb6637857089a99f (patch)
tree3ab621724f311f8b6356e5d490e1b170e4fe16f8
parentbdcf193c2e8da23189cb457026c7469a8f8e6369 (diff)
downloadglib-c8840ff9a8f8445e81ded935bb6637857089a99f.tar.gz
gthread: Only print scheduler setting warnings once
If one thread pool thread fails to set its scheduler settings, it’s likely that all the rest of them will fail for the same reason. Avoid printing duplicate critical warnings in that case. Signed-off-by: Philip Withnall <withnall@endlessm.com> Fixes: #2191
-rw-r--r--glib/gthread-posix.c6
1 files changed, 5 insertions, 1 deletions
diff --git a/glib/gthread-posix.c b/glib/gthread-posix.c
index 29bc81a0f..f36055925 100644
--- a/glib/gthread-posix.c
+++ b/glib/gthread-posix.c
@@ -1235,6 +1235,7 @@ static void *
linux_pthread_proxy (void *data)
{
GThreadPosix *thread = data;
+ static gboolean printed_scheduler_warning = FALSE; /* (atomic) */
/* Set scheduler settings first if requested */
if (thread->scheduler_settings)
@@ -1247,8 +1248,11 @@ linux_pthread_proxy (void *data)
tid = (pid_t) syscall (SYS_gettid);
res = syscall (SYS_sched_setattr, tid, thread->scheduler_settings->attr, flags);
errsv = errno;
- if (res == -1)
+ if (res == -1 && g_atomic_int_compare_and_exchange (&printed_scheduler_warning, FALSE, TRUE))
g_critical ("Failed to set scheduler settings: %s", g_strerror (errsv));
+ else if (res == -1)
+ g_debug ("Failed to set scheduler settings: %s", g_strerror (errsv));
+ printed_scheduler_warning = TRUE;
}
return thread->proxy (data);