summaryrefslogtreecommitdiff
path: root/src/basic/process-util.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/basic/process-util.c')
-rw-r--r--src/basic/process-util.c9
1 files changed, 9 insertions, 0 deletions
diff --git a/src/basic/process-util.c b/src/basic/process-util.c
index e0061d15b3..c5d7dc3089 100644
--- a/src/basic/process-util.c
+++ b/src/basic/process-util.c
@@ -585,3 +585,12 @@ bool pid_is_alive(pid_t pid) {
return true;
}
+
+bool is_main_thread(void) {
+ static thread_local int cached = 0;
+
+ if (_unlikely_(cached == 0))
+ cached = getpid() == gettid() ? 1 : -1;
+
+ return cached > 0;
+}