From: Christian Brauner Date: Fri, 24 Aug 2018 14:07:07 +0000 (+0200) Subject: compiler: add compiler.h header X-Git-Tag: lxc-3.1.0~127^2~24 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d7f19646dfacc7bc7a9cb7af1a44033f6d7de84f;p=thirdparty%2Flxc.git compiler: add compiler.h header Signed-off-by: Christian Brauner --- diff --git a/src/lxc/Makefile.am b/src/lxc/Makefile.am index 0322a0d65..266b2a36a 100644 --- a/src/lxc/Makefile.am +++ b/src/lxc/Makefile.am @@ -6,6 +6,7 @@ noinst_HEADERS = attach.h \ caps.h \ cgroups/cgroup.h \ cgroups/cgroup_utils.h \ + compiler.h \ conf.h \ confile.h \ confile_utils.h \ @@ -86,6 +87,7 @@ liblxc_la_SOURCES = af_unix.c af_unix.h \ cgroups/cgfsng.c \ cgroups/cgroup.c cgroups/cgroup.h \ cgroups/cgroup_utils.c cgroups/cgroup_utils.h \ + compiler.h \ commands.c commands.h \ commands_utils.c commands_utils.h \ conf.c conf.h \ diff --git a/src/lxc/compiler.h b/src/lxc/compiler.h new file mode 100644 index 000000000..cda44c987 --- /dev/null +++ b/src/lxc/compiler.h @@ -0,0 +1,35 @@ +/* liblxcapi + * + * Copyright © 2018 Christian Brauner . + * Copyright © 2018 Canonical Ltd. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2, as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#ifndef __LXC_COMPILER_H +#define __LXC_COMPILER_H + +#include "config.h" + +#ifndef thread_local +#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 + +#endif /* __LXC_COMPILER_H */ diff --git a/src/lxc/conf.c b/src/lxc/conf.c index dfca5923a..306633120 100644 --- a/src/lxc/conf.c +++ b/src/lxc/conf.c @@ -125,7 +125,7 @@ lxc_log_define(conf, lxc); * This is used in the error calls. */ #ifdef HAVE_TLS -__thread struct lxc_conf *current_config; +thread_local struct lxc_conf *current_config; #else struct lxc_conf *current_config; #endif diff --git a/src/lxc/conf.h b/src/lxc/conf.h index 070dd2292..eddf97a1a 100644 --- a/src/lxc/conf.h +++ b/src/lxc/conf.h @@ -38,6 +38,7 @@ #include #endif +#include "compiler.h" #include "list.h" #include "ringbuf.h" #include "start.h" /* for lxc_handler */ @@ -395,7 +396,7 @@ extern int write_id_mapping(enum idtype idtype, pid_t pid, const char *buf, size_t buf_size); #ifdef HAVE_TLS -extern __thread struct lxc_conf *current_config; +extern thread_local struct lxc_conf *current_config; #else extern struct lxc_conf *current_config; #endif diff --git a/src/lxc/initutils.c b/src/lxc/initutils.c index c582b2d00..467d3f0bc 100644 --- a/src/lxc/initutils.c +++ b/src/lxc/initutils.c @@ -28,6 +28,7 @@ #include "initutils.h" #include "log.h" #include "macro.h" +#include "compiler.h" #ifndef HAVE_STRLCPY #include "include/strlcpy.h" @@ -72,9 +73,9 @@ const char *lxc_global_config_value(const char *option_name) /* placed in the thread local storage pool for non-bionic targets */ #ifdef HAVE_TLS - static __thread const char *values[sizeof(options) / sizeof(options[0])] = { 0 }; + static thread_local const char *values[sizeof(options) / sizeof(options[0])] = {0}; #else - static const char *values[sizeof(options) / sizeof(options[0])] = { 0 }; + static const char *values[sizeof(options) / sizeof(options[0])] = {0}; #endif /* user_config_path is freed as soon as it is used */