From b09e06a92041b1031eff69e6807507261244e568 Mon Sep 17 00:00:00 2001 From: NRK Date: Sat, 5 Apr 2025 16:33:47 +0000 Subject: [PATCH] osdep/threads: prefer using thread_local C11 uses _Thread_local as the keyword, which thread_local macro is defined to (inside of , which mpv doesn't use): https://port70.net/~nsz/c/c11/n1570.html#7.26.1p3 C23 promotes thread_local to a keyword and marks _Thread_local as obsolete and to be avoided in new code: https://www.iso-9899.info/n3220.html#6.4.1p3 so just use thread_local directly, which is future-proof while having a fallback define in osdep/threads.h for pre-C23 cases. --- osdep/compiler.h | 4 ++++ osdep/io.c | 2 +- osdep/threads.h | 2 ++ 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/osdep/compiler.h b/osdep/compiler.h index cb04fed81f..48693154ce 100644 --- a/osdep/compiler.h +++ b/osdep/compiler.h @@ -22,6 +22,10 @@ #define MP_UNUSED #endif +#if defined(__STDC_VERSION__) && (__STDC_VERSION__ < 202311L) && !defined(thread_local) +#define thread_local _Thread_local +#endif + #if defined(__GNUC__) || defined(__clang__) #define PRINTF_ATTRIBUTE(a1, a2) __attribute__((format(printf, a1, a2))) #define SCANF_ATTRIBUTE(a1, a2) __attribute__((format(scanf, a1, a2))) diff --git a/osdep/io.c b/osdep/io.c index f7e24ba29a..5167b104a9 100644 --- a/osdep/io.c +++ b/osdep/io.c @@ -721,7 +721,7 @@ int mp_ftruncate64(int fd, off_t length) return -1; } -_Thread_local +thread_local static struct { DWORD errcode; char *errstring; diff --git a/osdep/threads.h b/osdep/threads.h index 4e9cf97baf..0e607598ff 100644 --- a/osdep/threads.h +++ b/osdep/threads.h @@ -9,4 +9,6 @@ #include "threads-posix.h" #endif +#include "osdep/compiler.h" // for thread_local + #endif