]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
Include <threads.h> if possible to get thread_local definition
authorCristian Rodríguez <crodriguez@owncloud.com>
Tue, 3 Jan 2023 17:52:08 +0000 (17:52 +0000)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Mon, 6 Mar 2023 01:04:39 +0000 (10:04 +0900)
IN C23, thread_local is a reserved keyword and we shall therefore
do nothing to redefine it. glibc has it defined for older standard
version with the right conditions.

v2 by Yu Watanabe:
Move the definition to missing_threads.h like the way we define e.g.
missing syscalls or missing definitions, and include it by the users.

Co-authored-by: Yu Watanabe <watanabe.yu+github@gmail.com>
22 files changed:
meson.build
src/basic/capability-util.c
src/basic/cgroup-util.c
src/basic/log.c
src/basic/macro.h
src/basic/memory-util.c
src/basic/missing_threads.h [new file with mode: 0644]
src/basic/process-util.c
src/basic/psi-util.c
src/basic/random-util.c
src/basic/signal-util.c
src/basic/time-util.c
src/basic/virt.c
src/libsystemd/sd-bus/sd-bus.c
src/libsystemd/sd-event/sd-event.c
src/libsystemd/sd-id128/sd-id128.c
src/libsystemd/sd-resolve/sd-resolve.c
src/login/logind-inhibit.c
src/network/networkd-route-util.c
src/nss-systemd/nss-systemd.c
src/shared/cgroup-setup.c
src/shared/uid-alloc-range.c

index 5e7cb92a83c59cd53c27870801fad55204585eb3..a274de560113d72358d39aff8b6130ae9256ed1b 100644 (file)
@@ -756,6 +756,7 @@ foreach header : ['crypt.h',
                   'linux/memfd.h',
                   'linux/vm_sockets.h',
                   'sys/auxv.h',
+                  'threads.h',
                   'valgrind/memcheck.h',
                   'valgrind/valgrind.h',
                   'linux/time_types.h',
index 87fb2203f0896650de9b106ee2004c643e71705c..1698ea02ccac425eb5e6863c756afa9edc2ac480 100644 (file)
@@ -14,6 +14,7 @@
 #include "logarithm.h"
 #include "macro.h"
 #include "missing_prctl.h"
+#include "missing_threads.h"
 #include "parse-util.h"
 #include "user-util.h"
 
index feda5969390c6f357600e0666c03191d0b1e1053..90877c9fa12be7f1a1c473563404fd116e6b7f1e 100644 (file)
@@ -23,6 +23,7 @@
 #include "login-util.h"
 #include "macro.h"
 #include "missing_magic.h"
+#include "missing_threads.h"
 #include "mkdir.h"
 #include "parse-util.h"
 #include "path-util.h"
index 6a4373101205a62b2a0368088f76a8672d696614..40602d5ddae2301469b00a954e30fb9c62a9848c 100644 (file)
@@ -25,6 +25,7 @@
 #include "log.h"
 #include "macro.h"
 #include "missing_syscall.h"
+#include "missing_threads.h"
 #include "parse-util.h"
 #include "proc-cmdline.h"
 #include "process-util.h"
index ddf3032fbc767a976cd2056cc9608917f9d638b5..2425d27819a35e0b6ef40eb01610815223b12c5b 100644 (file)
@@ -297,20 +297,6 @@ static inline int __coverity_check_and_return__(int condition) {
              p != (typeof(p)) POINTER_MAX;                                               \
              p = *(++_l))
 
-/* Define C11 thread_local attribute even on older gcc compiler
- * version */
-#ifndef thread_local
-/*
- * Don't break on glibc < 2.16 that doesn't define __STDC_NO_THREADS__
- * see https://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
-
 #define DEFINE_TRIVIAL_DESTRUCTOR(name, type, func)             \
         static inline void name(type *p) {                      \
                 func(p);                                        \
index c4f54c7b4ed97196d9fdb1391497b4e7230db80f..fcedae2d41b05925ca7a09852db7710cd4f6375f 100644 (file)
@@ -3,6 +3,7 @@
 #include <unistd.h>
 
 #include "memory-util.h"
+#include "missing_threads.h"
 
 size_t page_size(void) {
         static thread_local size_t pgsz = 0;
diff --git a/src/basic/missing_threads.h b/src/basic/missing_threads.h
new file mode 100644 (file)
index 0000000..fb3b722
--- /dev/null
@@ -0,0 +1,15 @@
+/* SPDX-License-Identifier: LGPL-2.1-or-later */
+#pragma once
+
+/* If threads.h doesn't exist, then define our own thread_local to match C11's thread_local. */
+#if HAVE_THREADS_H
+#  include <threads.h>
+#elif !(defined(thread_local))
+/* Don't break on glibc < 2.16 that doesn't define __STDC_NO_THREADS__
+ * see https://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
index 919387f958030053056c59668691c3562221b08c..5d499a57b4f015db0ac14c01647109cb6b177f96 100644 (file)
@@ -36,6 +36,7 @@
 #include "memory-util.h"
 #include "missing_sched.h"
 #include "missing_syscall.h"
+#include "missing_threads.h"
 #include "mountpoint-util.h"
 #include "namespace-util.h"
 #include "nulstr-util.h"
index a3b553cb440c732171b397aa24637c0896e3a402..af8e278bd0615565dfcb9dfe75670541881885fd 100644 (file)
@@ -8,6 +8,7 @@
 #include "extract-word.h"
 #include "fd-util.h"
 #include "fileio.h"
+#include "missing_threads.h"
 #include "parse-util.h"
 #include "psi-util.h"
 #include "string-util.h"
index 28ace92f194d3d88b5771d5c24c1917a999d449d..98bcc7444c51489bc49ac8a82e95b0fe697fabaa 100644 (file)
@@ -24,6 +24,7 @@
 #include "io-util.h"
 #include "missing_random.h"
 #include "missing_syscall.h"
+#include "missing_threads.h"
 #include "parse-util.h"
 #include "random-util.h"
 #include "sha256.h"
index 7875ca69bb7d2444764dbebbbfff647e2f6a16e1..5d9484626d86444c5253396fb6abce34f45be7c8 100644 (file)
@@ -6,6 +6,7 @@
 #include "errno-util.h"
 #include "macro.h"
 #include "missing_syscall.h"
+#include "missing_threads.h"
 #include "parse-util.h"
 #include "signal-util.h"
 #include "stdio-util.h"
index 26fd1bae6533bad887dfab35dcb6f57a50005646..e2c0d7ea9e3fbb1fd54008e7ec92f5daafc865ed 100644 (file)
@@ -17,6 +17,7 @@
 #include "io-util.h"
 #include "log.h"
 #include "macro.h"
+#include "missing_threads.h"
 #include "missing_timerfd.h"
 #include "parse-util.h"
 #include "path-util.h"
index ca3edaf3b54a03bd656ea1fd6b6c1e3e398a5b78..f264cc6eb3d787fb4ce20a7c4eda104e22f68fc7 100644 (file)
@@ -16,6 +16,7 @@
 #include "fd-util.h"
 #include "fileio.h"
 #include "macro.h"
+#include "missing_threads.h"
 #include "process-util.h"
 #include "stat-util.h"
 #include "string-table.h"
index 93d2a83bb0fc253f3edce3bf3a2116cd6ee4549a..5590cecfd9b00ac1d9e3937db7ecace7d2b3d4d4 100644 (file)
@@ -37,6 +37,7 @@
 #include "macro.h"
 #include "memory-util.h"
 #include "missing_syscall.h"
+#include "missing_threads.h"
 #include "parse-util.h"
 #include "path-util.h"
 #include "process-util.h"
index 2c0895dc741dc129b4fe417029baae39a4f2ba30..413ac16aa29b9e822a529b2c5259895bfc928b4f 100644 (file)
@@ -24,6 +24,7 @@
 #include "memory-util.h"
 #include "missing_magic.h"
 #include "missing_syscall.h"
+#include "missing_threads.h"
 #include "path-util.h"
 #include "prioq.h"
 #include "process-util.h"
index ec3a496dba5def1927ceeb06a70e99e1b013afe4..5ce36cf2fc9c51d3586aa506bde5773d6921d212 100644 (file)
@@ -14,6 +14,7 @@
 #include "io-util.h"
 #include "macro.h"
 #include "missing_syscall.h"
+#include "missing_threads.h"
 #include "random-util.h"
 #include "stat-util.h"
 #include "user-util.h"
index 48a92ac6153ce9b7f5347372e2d7dfcc3114a0b3..f1c7e0a2dae0f44b487f33509f756334af00addf 100644 (file)
@@ -22,6 +22,7 @@
 #include "list.h"
 #include "memory-util.h"
 #include "missing_syscall.h"
+#include "missing_threads.h"
 #include "process-util.h"
 #include "resolve-private.h"
 #include "socket-util.h"
index 8735538d209ce4f0747327bb86e8f7a26e58700d..12cd854706d6c5f3b6b924f27bb464f7a18dde3b 100644 (file)
@@ -18,6 +18,7 @@
 #include "io-util.h"
 #include "logind-dbus.h"
 #include "logind-inhibit.h"
+#include "missing_threads.h"
 #include "mkdir-label.h"
 #include "parse-util.h"
 #include "path-util.h"
index 84866d3f84b6bce5f000ce90f0a54aab6a6924a8..e497f059965786c46537ea4bf48138f244b7decc 100644 (file)
@@ -4,6 +4,7 @@
 
 #include "alloc-util.h"
 #include "logarithm.h"
+#include "missing_threads.h"
 #include "networkd-address.h"
 #include "networkd-link.h"
 #include "networkd-manager.h"
index 75d749e736da1631abaff8156c7c0148aa3ef364..1d6e25399f626701a1de643a5d457f1c06088d08 100644 (file)
@@ -9,6 +9,7 @@
 #include "fd-util.h"
 #include "log.h"
 #include "macro.h"
+#include "missing_threads.h"
 #include "nss-systemd.h"
 #include "nss-util.h"
 #include "pthread-util.h"
index 2ea83f05d317e09cfb1a6b7797bcdb010e952eea..65be85101408bba80e2aecc0bc873cb817040b6d 100644 (file)
@@ -8,6 +8,7 @@
 #include "fd-util.h"
 #include "fileio.h"
 #include "fs-util.h"
+#include "missing_threads.h"
 #include "mkdir.h"
 #include "parse-util.h"
 #include "path-util.h"
index dcecdbe34381533b8cfd2f8469b7ada8fdae3b13..195311942250965ac4b95db835f1e58a95c82cf0 100644 (file)
@@ -3,6 +3,7 @@
 #include "chase-symlinks.h"
 #include "fd-util.h"
 #include "fileio.h"
+#include "missing_threads.h"
 #include "string-util.h"
 #include "uid-alloc-range.h"
 #include "user-util.h"