From 07612aab66dc771a9c7aca07c74940fb6447f3fa Mon Sep 17 00:00:00 2001 From: Mike Yuan Date: Wed, 20 Nov 2024 15:12:25 +0100 Subject: [PATCH] process-util: use our usual tristate semantics for is_main_thread() While at it, _unlikely_ is dropped, as requested in https://github.com/systemd/systemd/pull/35242#discussion_r1880096233 --- src/basic/process-util.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/basic/process-util.c b/src/basic/process-util.c index 3253a9c3fb0..59dfaa07f3d 100644 --- a/src/basic/process-util.c +++ b/src/basic/process-util.c @@ -1226,12 +1226,12 @@ int pid_from_same_root_fs(pid_t pid) { } bool is_main_thread(void) { - static thread_local int cached = 0; + static thread_local int cached = -1; - if (_unlikely_(cached == 0)) - cached = getpid_cached() == gettid() ? 1 : -1; + if (cached < 0) + cached = getpid_cached() == gettid(); - return cached > 0; + return cached; } bool oom_score_adjust_is_valid(int oa) { -- 2.47.3