diff options
author | Lennart Poettering <lennart@poettering.net> | 2015-10-27 00:02:45 +0100 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2015-10-27 13:25:57 +0100 |
commit | d4510856a007712900795c79853d2218780c2321 (patch) | |
tree | 3c9bf5662f4017a6763c78d638e1e38b1a2ccdf4 /src/basic/process-util.c | |
parent | 430f0182b72373145c839dbfe99d2382855cb8f8 (diff) |
util-lib: move is_main_thread() to process-util.[ch]
Diffstat (limited to 'src/basic/process-util.c')
-rw-r--r-- | src/basic/process-util.c | 9 |
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; +} |