summaryrefslogtreecommitdiff
path: root/src/util.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2011-08-01 05:05:12 +0200
committerLennart Poettering <lennart@poettering.net>2011-08-01 05:05:12 +0200
commitb636465bc0190448f960791cd059c4dd1fa37717 (patch)
tree03484804e0ce940f20e90592db839726c1b66767 /src/util.c
parentcd0ed1db9b58900959866e7b265fae2b153b68c0 (diff)
util: add is_main_thread() call
Diffstat (limited to 'src/util.c')
-rw-r--r--src/util.c9
1 files changed, 9 insertions, 0 deletions
diff --git a/src/util.c b/src/util.c
index 6382c01c55..4e2a4fab83 100644
--- a/src/util.c
+++ b/src/util.c
@@ -5536,6 +5536,15 @@ char *join(const char *x, ...) {
return r;
}
+bool is_main_thread(void) {
+ static __thread int cached = 0;
+
+ if (_unlikely_(cached == 0))
+ cached = getpid() == gettid() ? 1 : -1;
+
+ return cached > 0;
+}
+
static const char *const ioprio_class_table[] = {
[IOPRIO_CLASS_NONE] = "none",
[IOPRIO_CLASS_RT] = "realtime",