]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
process-util: use our usual tristate semantics for is_main_thread()
authorMike Yuan <me@yhndnzj.com>
Wed, 20 Nov 2024 14:12:25 +0000 (15:12 +0100)
committerMike Yuan <me@yhndnzj.com>
Wed, 11 Dec 2024 13:44:07 +0000 (14:44 +0100)
While at it, _unlikely_ is dropped, as requested in
https://github.com/systemd/systemd/pull/35242#discussion_r1880096233

src/basic/process-util.c

index 3253a9c3fb02036407cd95cb2ac9c26d95918a02..59dfaa07f3d8cd7962a00c8129675924fcc049e7 100644 (file)
@@ -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) {