mirror of
https://github.com/systemd/systemd.git
synced 2025-01-09 01:18:19 +03:00
Include <threads.h> if possible to get thread_local definition
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>
This commit is contained in:
parent
efcde781de
commit
5545f336fd
@ -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',
|
||||
|
@ -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"
|
||||
|
||||
|
@ -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"
|
||||
|
@ -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"
|
||||
|
@ -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); \
|
||||
|
@ -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;
|
||||
|
15
src/basic/missing_threads.h
Normal file
15
src/basic/missing_threads.h
Normal file
@ -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
|
@ -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"
|
||||
|
@ -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"
|
||||
|
@ -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"
|
||||
|
@ -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"
|
||||
|
@ -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"
|
||||
|
@ -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"
|
||||
|
@ -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"
|
||||
|
@ -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"
|
||||
|
@ -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"
|
||||
|
@ -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"
|
||||
|
@ -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"
|
||||
|
@ -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"
|
||||
|
@ -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"
|
||||
|
@ -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"
|
||||
|
@ -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"
|
||||
|
Loading…
Reference in New Issue
Block a user