__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)
This commit is contained in:
Shawn Landden 2013-12-15 16:24:14 -08:00 committed by Lennart Poettering
parent 06db8540cd
commit ec202eae8e
9 changed files with 30 additions and 18 deletions

View 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) {
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) {
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);
}

View 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) {
static __thread sd_event *default_event = NULL;
static thread_local sd_event *default_event = NULL;
sd_event *e;
int r;

View 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) {
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;
@ -153,8 +153,8 @@ _public_ int sd_id128_get_machine(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;

View File

@ -413,7 +413,7 @@ bool manager_is_inhibited(
}
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)

View File

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

View 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;
static __thread bool good = false;
static thread_local bool good = false;
assert(fs);

View File

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

View File

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

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