]> err.no Git - systemd/commitdiff
util: add is_main_thread() call
authorLennart Poettering <lennart@poettering.net>
Mon, 1 Aug 2011 03:05:12 +0000 (05:05 +0200)
committerLennart Poettering <lennart@poettering.net>
Mon, 1 Aug 2011 03:05:12 +0000 (05:05 +0200)
src/util.c
src/util.h

index 6382c01c556eb7d7f0e83f1de62338909b248f78..4e2a4fab832f8c98c578097d0e4ba4857db2d67b 100644 (file)
@@ -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",
index eb0061cdb5dee6e5913565fa836363921d6ebea6..407160d528c88eda7e4092bf496851f24098b57b 100644 (file)
@@ -460,6 +460,8 @@ int get_files_in_directory(const char *path, char ***list);
 
 char *join(const char *x, ...) _sentinel_;
 
+bool is_main_thread(void);
+
 #define NULSTR_FOREACH(i, l)                                    \
         for ((i) = (l); (i) && *(i); (i) = strchr((i), 0)+1)