From: Lennart Poettering Date: Mon, 26 Oct 2015 23:02:45 +0000 (+0100) Subject: util-lib: move is_main_thread() to process-util.[ch] X-Git-Tag: v228~140^2~24 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=d4510856a007712900795c79853d2218780c2321;p=thirdparty%2Fsystemd.git util-lib: move is_main_thread() to process-util.[ch] --- diff --git a/src/basic/hashmap.c b/src/basic/hashmap.c index 20e7e51d9e2..015cc629b17 100644 --- a/src/basic/hashmap.c +++ b/src/basic/hashmap.c @@ -20,18 +20,19 @@ along with systemd; If not, see . ***/ -#include #include #include +#include -#include "util.h" #include "hashmap.h" -#include "set.h" #include "macro.h" -#include "siphash24.h" -#include "strv.h" #include "mempool.h" +#include "process-util.h" #include "random-util.h" +#include "set.h" +#include "siphash24.h" +#include "strv.h" +#include "util.h" #ifdef ENABLE_DEBUG_HASHMAP #include "list.h" diff --git a/src/basic/process-util.c b/src/basic/process-util.c index e0061d15b3d..c5d7dc3089e 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; +} diff --git a/src/basic/process-util.h b/src/basic/process-util.h index 2c0d1af0006..d17df5d81fc 100644 --- a/src/basic/process-util.h +++ b/src/basic/process-util.h @@ -66,3 +66,5 @@ int getenv_for_pid(pid_t pid, const char *field, char **_value); bool pid_is_alive(pid_t pid); bool pid_is_unwaited(pid_t pid); + +bool is_main_thread(void); diff --git a/src/basic/util.c b/src/basic/util.c index b079e8af169..6fe4f47018f 100644 --- a/src/basic/util.c +++ b/src/basic/util.c @@ -421,15 +421,6 @@ int glob_extend(char ***strv, const char *path) { return k; } -bool is_main_thread(void) { - static thread_local int cached = 0; - - if (_unlikely_(cached == 0)) - cached = getpid() == gettid() ? 1 : -1; - - return cached > 0; -} - int block_get_whole_disk(dev_t d, dev_t *ret) { char *p, *s; int r; diff --git a/src/basic/util.h b/src/basic/util.h index e356f59cd5c..96be6ecaa85 100644 --- a/src/basic/util.h +++ b/src/basic/util.h @@ -103,8 +103,6 @@ int socket_from_display(const char *display, char **path); int glob_exists(const char *path); int glob_extend(char ***strv, const char *path); -bool is_main_thread(void); - int block_get_whole_disk(dev_t d, dev_t *ret); #define NULSTR_FOREACH(i, l) \