summaryrefslogtreecommitdiff
path: root/src/shared
diff options
context:
space:
mode:
authorShawn Landden <shawn@churchofgit.com>2013-12-15 16:24:14 -0800
committerLennart Poettering <lennart@poettering.net>2013-12-17 21:45:43 +0100
commitec202eae8e84a4c99f054f771cb832046cb8769f (patch)
tree3342ddcf1d386c7f613b60e3d72477580eb7ba06 /src/shared
parent06db8540cdfc8259423ed90e7352dbc1d71eccd9 (diff)
__thread --> thread_local for C11 compat
Also make thread_local available w/o including <threads.h>. (as the latter hasn't been implemented, but this part is trivial)
Diffstat (limited to 'src/shared')
-rw-r--r--src/shared/capability.c4
-rw-r--r--src/shared/cgroup-util.c2
-rw-r--r--src/shared/macro.h12
-rw-r--r--src/shared/util.c6
-rw-r--r--src/shared/virt.c8
5 files changed, 22 insertions, 10 deletions
diff --git a/src/shared/capability.c b/src/shared/capability.c
index 321952067d..f34f6ba6f6 100644
--- a/src/shared/capability.c
+++ b/src/shared/capability.c
@@ -55,8 +55,8 @@ int have_effective_cap(int value) {
}
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)
diff --git a/src/shared/cgroup-util.c b/src/shared/cgroup-util.c
index 2c2ffc5898..309f65d03e 100644
--- a/src/shared/cgroup-util.c
+++ b/src/shared/cgroup-util.c
@@ -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;
- static __thread bool good = false;
+ static thread_local bool good = false;
assert(fs);
diff --git a/src/shared/macro.h b/src/shared/macro.h
index fd3762eed4..2b5b3fdfe0 100644
--- a/src/shared/macro.h
+++ b/src/shared/macro.h
@@ -300,5 +300,17 @@ do { \
_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"
diff --git a/src/shared/util.c b/src/shared/util.c
index cdc58e394f..f7335cf279 100644
--- a/src/shared/util.c
+++ b/src/shared/util.c
@@ -86,7 +86,7 @@ static volatile unsigned cached_columns = 0;
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))
@@ -4580,7 +4580,7 @@ char *strjoin(const char *x, ...) {
}
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;
@@ -4798,7 +4798,7 @@ static const char *const __signal_table[] = {
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);
diff --git a/src/shared/virt.c b/src/shared/virt.c
index 4e18638bc9..c79d35db4d 100644
--- a/src/shared/virt.c
+++ b/src/shared/virt.c
@@ -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;
- 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;
@@ -215,8 +215,8 @@ finish:
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;