From f2d4dac92efa78717b484a96a4b2c134832afbef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Verschelde?= Date: Wed, 1 Jan 2025 21:49:16 +0100 Subject: [PATCH] Thread: Re-add `` include for `std::hardware_destructive_interference_size` Somehow it would still build fine, but would crash when compiled with GCC 12.2 on Debian 12. Also re-add wrongly removed Mutex include from `thread_safe.h`, where it's used in macros. Add IWYU pragma comments to prevent it from mistakenly flagging those as unused. --- core/os/thread.cpp | 4 ++-- core/os/thread.h | 19 ++++++++++++++----- core/os/thread_safe.h | 2 ++ 3 files changed, 18 insertions(+), 7 deletions(-) diff --git a/core/os/thread.cpp b/core/os/thread.cpp index afc74364f65..3992eb31bf5 100644 --- a/core/os/thread.cpp +++ b/core/os/thread.cpp @@ -29,13 +29,13 @@ /**************************************************************************/ #include "platform_config.h" -#ifndef PLATFORM_THREAD_OVERRIDE // See details in thread.h + +#ifndef PLATFORM_THREAD_OVERRIDE // See details in thread.h. #include "thread.h" #ifdef THREADS_ENABLED #include "core/object/script_language.h" -#include "core/templates/safe_refcount.h" SafeNumeric Thread::id_counter(1); // The first value after .increment() is 2, hence by default the main thread ID should be 1. diff --git a/core/os/thread.h b/core/os/thread.h index 066c4befa77..9042c6c0171 100644 --- a/core/os/thread.h +++ b/core/os/thread.h @@ -29,19 +29,28 @@ /**************************************************************************/ #include "platform_config.h" + // Define PLATFORM_THREAD_OVERRIDE in your platform's `platform_config.h` -// to use a custom Thread implementation defined in `platform/[your_platform]/platform_thread.h` -// Overriding the platform implementation is required in some proprietary platforms +// to use a custom Thread implementation defined in `platform/[your_platform]/platform_thread.h`. +// Overriding the Thread implementation is required in some proprietary platforms. + #ifdef PLATFORM_THREAD_OVERRIDE + #include "platform_thread.h" + #else #ifndef THREAD_H #define THREAD_H -#include "core/templates/safe_refcount.h" #include "core/typedefs.h" +#ifdef THREADS_ENABLED + +#include "core/templates/safe_refcount.h" + +#include // IWYU pragma: keep // For hardware interference size. + #ifdef MINGW_ENABLED #define MINGW_STDTHREAD_REDUNDANCY_WARNING #include "thirdparty/mingw-std-threads/mingw.thread.h" @@ -53,8 +62,6 @@ class String; -#ifdef THREADS_ENABLED - class Thread { public: typedef void (*Callback)(void *p_userdata); @@ -143,6 +150,8 @@ public: #else // No threads. +class String; + class Thread { public: typedef void (*Callback)(void *p_userdata); diff --git a/core/os/thread_safe.h b/core/os/thread_safe.h index 316b0c96876..f49592a4ecb 100644 --- a/core/os/thread_safe.h +++ b/core/os/thread_safe.h @@ -31,6 +31,8 @@ #ifndef THREAD_SAFE_H #define THREAD_SAFE_H +#include "core/os/mutex.h" // IWYU pragma: keep // Used in macro. + #define _THREAD_SAFE_CLASS_ mutable Mutex _thread_safe_; #define _THREAD_SAFE_METHOD_ MutexLock _thread_safe_method_(_thread_safe_); #define _THREAD_SAFE_LOCK_ _thread_safe_.lock();