chiark / gitweb /
__thread --> thread_local for C11 compat
authorShawn Landden <shawn@churchofgit.com>
Mon, 16 Dec 2013 00:24:14 +0000 (16:24 -0800)
committerLennart Poettering <lennart@poettering.net>
Tue, 17 Dec 2013 20:45:43 +0000 (21:45 +0100)
Also make thread_local available w/o including <threads.h>.
(as the latter hasn't been implemented, but this part is trivial)

src/libsystemd-bus/sd-bus.c
src/libsystemd-bus/sd-event.c
src/libsystemd-id128/sd-id128.c
src/login/logind-inhibit.c
src/shared/capability.c
src/shared/cgroup-util.c
src/shared/macro.h
src/shared/util.c
src/shared/virt.c

index 338ce0619d0016720e4bd5d66891c8790d626a9c..9c564de76403b9c928b95e504374df9f062f738d 100644 (file)
@@ -2813,13 +2813,13 @@ static int bus_default(int (*bus_open)(sd_bus **), sd_bus **default_bus, sd_bus
 }
 
 _public_ int sd_bus_default_system(sd_bus **ret) {
 }
 
 _public_ int sd_bus_default_system(sd_bus **ret) {
-        static __thread sd_bus *default_system_bus = NULL;
+        static thread_local sd_bus *default_system_bus = NULL;
 
         return bus_default(sd_bus_open_system, &default_system_bus, ret);
 }
 
 _public_ int sd_bus_default_user(sd_bus **ret) {
 
         return bus_default(sd_bus_open_system, &default_system_bus, ret);
 }
 
 _public_ int sd_bus_default_user(sd_bus **ret) {
-        static __thread sd_bus *default_user_bus = NULL;
+        static thread_local sd_bus *default_user_bus = NULL;
 
         return bus_default(sd_bus_open_user, &default_user_bus, ret);
 }
 
         return bus_default(sd_bus_open_user, &default_user_bus, ret);
 }
index 06c84d717ab23a8c3359fac1c92c4166768e2abe..727528bb3cc84e839e3c180d1812497165c159ec 100644 (file)
@@ -2116,7 +2116,7 @@ _public_ int sd_event_get_now_monotonic(sd_event *e, uint64_t *usec) {
 
 _public_ int sd_event_default(sd_event **ret) {
 
 
 _public_ int sd_event_default(sd_event **ret) {
 
-        static __thread sd_event *default_event = NULL;
+        static thread_local sd_event *default_event = NULL;
         sd_event *e;
         int r;
 
         sd_event *e;
         int r;
 
index 07d241534e53378c1d4c6a9042396264b58a28fe..9ee40ab91eaaee64a3f13dc61dc354bc8de26400 100644 (file)
@@ -104,8 +104,8 @@ static sd_id128_t make_v4_uuid(sd_id128_t id) {
 }
 
 _public_ int sd_id128_get_machine(sd_id128_t *ret) {
 }
 
 _public_ int sd_id128_get_machine(sd_id128_t *ret) {
-        static __thread sd_id128_t saved_machine_id;
-        static __thread bool saved_machine_id_valid = false;
+        static thread_local sd_id128_t saved_machine_id;
+        static thread_local bool saved_machine_id_valid = false;
         _cleanup_close_ int fd = -1;
         char buf[33];
         ssize_t k;
         _cleanup_close_ int fd = -1;
         char buf[33];
         ssize_t k;
@@ -153,8 +153,8 @@ _public_ int sd_id128_get_machine(sd_id128_t *ret) {
 }
 
 _public_ int sd_id128_get_boot(sd_id128_t *ret) {
 }
 
 _public_ int sd_id128_get_boot(sd_id128_t *ret) {
-        static __thread sd_id128_t saved_boot_id;
-        static __thread bool saved_boot_id_valid = false;
+        static thread_local sd_id128_t saved_boot_id;
+        static thread_local bool saved_boot_id_valid = false;
         _cleanup_close_ int fd = -1;
         char buf[36];
         ssize_t k;
         _cleanup_close_ int fd = -1;
         char buf[36];
         ssize_t k;
index ec6a722ce3e65ed7b1517c7d65098d249aaad7b6..042586d0738c9268ae54bc8ce07a04c0b3465293 100644 (file)
@@ -413,7 +413,7 @@ bool manager_is_inhibited(
 }
 
 const char *inhibit_what_to_string(InhibitWhat w) {
 }
 
 const char *inhibit_what_to_string(InhibitWhat w) {
-        static __thread char buffer[97];
+        static thread_local char buffer[97];
         char *p;
 
         if (w < 0 || w >= _INHIBIT_WHAT_MAX)
         char *p;
 
         if (w < 0 || w >= _INHIBIT_WHAT_MAX)
index 321952067d71469c3e9c683ff85c191695dac730..f34f6ba6f690c769004cabd7bfad4070f2664a94 100644 (file)
@@ -55,8 +55,8 @@ int have_effective_cap(int value) {
 }
 
 unsigned long cap_last_cap(void) {
 }
 
 unsigned long cap_last_cap(void) {
-        static __thread unsigned long saved;
-        static __thread bool valid = false;
+        static thread_local unsigned long saved;
+        static thread_local bool valid = false;
         unsigned long p;
 
         if (valid)
         unsigned long p;
 
         if (valid)
index 2c2ffc589879ead8b7f04c2cf31bcff833d428cb..309f65d03eefc0cff9c046db035883565b9fdcc9 100644 (file)
@@ -480,7 +480,7 @@ static int join_path(const char *controller, const char *path, const char *suffi
 
 int cg_get_path(const char *controller, const char *path, const char *suffix, char **fs) {
         const char *p;
 
 int cg_get_path(const char *controller, const char *path, const char *suffix, char **fs) {
         const char *p;
-        static __thread bool good = false;
+        static thread_local bool good = false;
 
         assert(fs);
 
 
         assert(fs);
 
index fd3762eed4aae50976bff45148966dbde4cb6764..2b5b3fdfe0038e3c74e419441f7621f68aad9d29 100644 (file)
@@ -300,5 +300,17 @@ do {                                                                    \
                 _found;                                                 \
         })
 
                 _found;                                                 \
         })
 
+/* Define C11 thread_local attribute even on older compilers */
+#ifndef thread_local
+/*
+ * Don't break on glibc < 2.16 that doesn't define __STDC_NO_THREADS__
+ * see http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53769
+ */
+#if __STDC_VERSION__ >= 201112L && !(defined(__STDC_NO_THREADS__) || (defined(__GNU_LIBRARY__) && __GLIBC__ == 2 && __GLIBC_MINOR__ < 16))
+#define thread_local _Thread_local
+#else
+#define thread_local __thread
+#endif
+#endif
 
 #include "log.h"
 
 #include "log.h"
index cdc58e394f1e77fbe9ed329dc2054ae299d03c77..f7335cf279770bbc0d8f243b06205d1d53c23b33 100644 (file)
@@ -86,7 +86,7 @@ static volatile unsigned cached_columns = 0;
 static volatile unsigned cached_lines = 0;
 
 size_t page_size(void) {
 static volatile unsigned cached_lines = 0;
 
 size_t page_size(void) {
-        static __thread size_t pgsz = 0;
+        static thread_local size_t pgsz = 0;
         long r;
 
         if (_likely_(pgsz > 0))
         long r;
 
         if (_likely_(pgsz > 0))
@@ -4580,7 +4580,7 @@ char *strjoin(const char *x, ...) {
 }
 
 bool is_main_thread(void) {
 }
 
 bool is_main_thread(void) {
-        static __thread int cached = 0;
+        static thread_local int cached = 0;
 
         if (_unlikely_(cached == 0))
                 cached = getpid() == gettid() ? 1 : -1;
 
         if (_unlikely_(cached == 0))
                 cached = getpid() == gettid() ? 1 : -1;
@@ -4798,7 +4798,7 @@ static const char *const __signal_table[] = {
 DEFINE_PRIVATE_STRING_TABLE_LOOKUP(__signal, int);
 
 const char *signal_to_string(int signo) {
 DEFINE_PRIVATE_STRING_TABLE_LOOKUP(__signal, int);
 
 const char *signal_to_string(int signo) {
-        static __thread char buf[sizeof("RTMIN+")-1 + DECIMAL_STR_MAX(int) + 1];
+        static thread_local char buf[sizeof("RTMIN+")-1 + DECIMAL_STR_MAX(int) + 1];
         const char *name;
 
         name = __signal_to_string(signo);
         const char *name;
 
         name = __signal_to_string(signo);
index 4e18638bc9e421ce842b8bbc2322bc7b1d5d81c3..c79d35db4dd258d17db20b2a66c02a3c9a258411 100644 (file)
@@ -150,8 +150,8 @@ static int detect_vm_dmi(const char **_id) {
 /* Returns a short identifier for the various VM implementations */
 int detect_vm(const char **id) {
         _cleanup_free_ char *hvtype = NULL, *cpuinfo_contents = NULL;
 /* Returns a short identifier for the various VM implementations */
 int detect_vm(const char **id) {
         _cleanup_free_ char *hvtype = NULL, *cpuinfo_contents = NULL;
-        static __thread int cached_found = -1;
-        static __thread const char *cached_id = NULL;
+        static thread_local int cached_found = -1;
+        static thread_local const char *cached_id = NULL;
         const char *_id = NULL;
         int r;
 
         const char *_id = NULL;
         int r;
 
@@ -215,8 +215,8 @@ finish:
 
 int detect_container(const char **id) {
 
 
 int detect_container(const char **id) {
 
-        static __thread int cached_found = -1;
-        static __thread const char *cached_id = NULL;
+        static thread_local int cached_found = -1;
+        static thread_local const char *cached_id = NULL;
 
         _cleanup_free_ char *e = NULL;
         const char *_id = NULL;
 
         _cleanup_free_ char *e = NULL;
         const char *_id = NULL;