Skip to content

Commit

Permalink
Add a utility cache line size constant
Browse files Browse the repository at this point in the history
  • Loading branch information
RandomShaper committed Nov 4, 2024
1 parent 1bffd6c commit 548c463
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
1 change: 1 addition & 0 deletions SConstruct
Original file line number Diff line number Diff line change
Expand Up @@ -851,6 +851,7 @@ if env.msvc and not methods.using_clang(env): # MSVC
"/wd4245",
"/wd4267",
"/wd4305", # C4305 (truncation): double to float or real_t, too hard to avoid.
"/wd4324", # C4820 (structure was padded due to alignment specifier)
"/wd4514", # C4514 (unreferenced inline function has been removed)
"/wd4714", # C4714 (function marked as __forceinline not inlined)
"/wd4820", # C4820 (padding added after construct)
Expand Down
17 changes: 17 additions & 0 deletions core/os/thread.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@
#include "core/templates/safe_refcount.h"
#include "core/typedefs.h"

#include <new>

#ifdef MINGW_ENABLED
#define MINGW_STDTHREAD_REDUNDANCY_WARNING
#include "thirdparty/mingw-std-threads/mingw.thread.h"
Expand Down Expand Up @@ -85,6 +87,19 @@ class Thread {
void (*term)() = nullptr;
};

#if defined(__cpp_lib_hardware_interference_size) && !defined(ANDROID_ENABLED) // This would be OK with NDK >= 26.
#if defined(__GNUC__) && !defined(__clang__)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Winterference-size"
#endif
static constexpr size_t CACHE_LINE_BYTES = std::hardware_destructive_interference_size;
#if defined(__GNUC__) && !defined(__clang__)
#pragma GCC diagnostic pop
#endif
#else
static constexpr size_t CACHE_LINE_BYTES = 64;
#endif

private:
friend class Main;

Expand Down Expand Up @@ -135,6 +150,8 @@ class Thread {

typedef uint64_t ID;

static constexpr size_t CACHE_LINE_BYTES = sizeof(void *);

enum : ID {
UNASSIGNED_ID = 0,
MAIN_ID = 1
Expand Down

0 comments on commit 548c463

Please sign in to comment.