1
1
mirror of https://github.com/systemd/systemd-stable.git synced 2025-01-10 01:17:44 +03:00

util-lib: move is_main_thread() to process-util.[ch]

This commit is contained in:
Lennart Poettering 2015-10-27 00:02:45 +01:00
parent 430f0182b7
commit d4510856a0
5 changed files with 17 additions and 16 deletions

View File

@ -20,18 +20,19 @@
along with systemd; If not, see <http://www.gnu.org/licenses/>.
***/
#include <stdlib.h>
#include <errno.h>
#include <pthread.h>
#include <stdlib.h>
#include "util.h"
#include "hashmap.h"
#include "set.h"
#include "macro.h"
#include "mempool.h"
#include "process-util.h"
#include "random-util.h"
#include "set.h"
#include "siphash24.h"
#include "strv.h"
#include "mempool.h"
#include "random-util.h"
#include "util.h"
#ifdef ENABLE_DEBUG_HASHMAP
#include "list.h"

View File

@ -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;
}

View File

@ -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);

View File

@ -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;

View File

@ -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) \