1
0
Fork 0

Thread: Re-add `<new>` 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.
This commit is contained in:
Rémi Verschelde 2025-01-01 21:49:16 +01:00
parent 2582793d40
commit f2d4dac92e
No known key found for this signature in database
GPG Key ID: C3336907360768E1
3 changed files with 18 additions and 7 deletions

View File

@ -29,13 +29,13 @@
/**************************************************************************/ /**************************************************************************/
#include "platform_config.h" #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" #include "thread.h"
#ifdef THREADS_ENABLED #ifdef THREADS_ENABLED
#include "core/object/script_language.h" #include "core/object/script_language.h"
#include "core/templates/safe_refcount.h"
SafeNumeric<uint64_t> Thread::id_counter(1); // The first value after .increment() is 2, hence by default the main thread ID should be 1. SafeNumeric<uint64_t> Thread::id_counter(1); // The first value after .increment() is 2, hence by default the main thread ID should be 1.

View File

@ -29,19 +29,28 @@
/**************************************************************************/ /**************************************************************************/
#include "platform_config.h" #include "platform_config.h"
// Define PLATFORM_THREAD_OVERRIDE in your platform's `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` // to use a custom Thread implementation defined in `platform/[your_platform]/platform_thread.h`.
// Overriding the platform implementation is required in some proprietary platforms // Overriding the Thread implementation is required in some proprietary platforms.
#ifdef PLATFORM_THREAD_OVERRIDE #ifdef PLATFORM_THREAD_OVERRIDE
#include "platform_thread.h" #include "platform_thread.h"
#else #else
#ifndef THREAD_H #ifndef THREAD_H
#define THREAD_H #define THREAD_H
#include "core/templates/safe_refcount.h"
#include "core/typedefs.h" #include "core/typedefs.h"
#ifdef THREADS_ENABLED
#include "core/templates/safe_refcount.h"
#include <new> // IWYU pragma: keep // For hardware interference size.
#ifdef MINGW_ENABLED #ifdef MINGW_ENABLED
#define MINGW_STDTHREAD_REDUNDANCY_WARNING #define MINGW_STDTHREAD_REDUNDANCY_WARNING
#include "thirdparty/mingw-std-threads/mingw.thread.h" #include "thirdparty/mingw-std-threads/mingw.thread.h"
@ -53,8 +62,6 @@
class String; class String;
#ifdef THREADS_ENABLED
class Thread { class Thread {
public: public:
typedef void (*Callback)(void *p_userdata); typedef void (*Callback)(void *p_userdata);
@ -143,6 +150,8 @@ public:
#else // No threads. #else // No threads.
class String;
class Thread { class Thread {
public: public:
typedef void (*Callback)(void *p_userdata); typedef void (*Callback)(void *p_userdata);

View File

@ -31,6 +31,8 @@
#ifndef THREAD_SAFE_H #ifndef THREAD_SAFE_H
#define 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_CLASS_ mutable Mutex _thread_safe_;
#define _THREAD_SAFE_METHOD_ MutexLock _thread_safe_method_(_thread_safe_); #define _THREAD_SAFE_METHOD_ MutexLock _thread_safe_method_(_thread_safe_);
#define _THREAD_SAFE_LOCK_ _thread_safe_.lock(); #define _THREAD_SAFE_LOCK_ _thread_safe_.lock();