Remove DWORD from shared TLS keys

This commit is contained in:
notmatthewbeshay
2026-03-14 06:28:46 +11:00
parent f4d8815285
commit 2180aaa4bc
12 changed files with 74 additions and 56 deletions
+4 -4
View File
@@ -23,12 +23,12 @@ const float PistonBaseTile::PLATFORM_THICKNESS = 4.0f;
namespace namespace
{ {
#if defined(_WIN32) #if defined(_WIN32)
inline void *PistonTlsGetValue(DWORD key) inline void *PistonTlsGetValue(PistonBaseTile::TlsKey key)
{ {
return TlsGetValue(key); return TlsGetValue(key);
} }
inline void PistonTlsSetValue(DWORD key, void *value) inline void PistonTlsSetValue(PistonBaseTile::TlsKey key, void *value)
{ {
TlsSetValue(key, value); TlsSetValue(key, value);
} }
@@ -53,9 +53,9 @@ namespace
} }
#if defined(_WIN32) #if defined(_WIN32)
DWORD PistonBaseTile::tlsIdx = TlsAlloc(); PistonBaseTile::TlsKey PistonBaseTile::tlsIdx = TlsAlloc();
#else #else
pthread_key_t PistonBaseTile::tlsIdx = CreatePistonTlsKey(); PistonBaseTile::TlsKey PistonBaseTile::tlsIdx = CreatePistonTlsKey();
#endif #endif
// 4J - NOTE - this ignoreUpdate stuff has been removed from the java version, but I'm not currently sure how the java version does without it... there must be // 4J - NOTE - this ignoreUpdate stuff has been removed from the java version, but I'm not currently sure how the java version does without it... there must be
+8 -5
View File
@@ -1,5 +1,6 @@
#pragma once #pragma once
#include "Tile.h" #include "Tile.h"
#include <cstdint>
#if !defined(_WIN32) #if !defined(_WIN32)
#include <pthread.h> #include <pthread.h>
@@ -8,6 +9,12 @@
class PistonBaseTile : public Tile class PistonBaseTile : public Tile
{ {
public: public:
#if defined(_WIN32)
using TlsKey = std::uint32_t;
#else
using TlsKey = pthread_key_t;
#endif
static const int EXTENDED_BIT = 8; static const int EXTENDED_BIT = 8;
static const int UNDEFINED_FACING = 7; static const int UNDEFINED_FACING = 7;
@@ -29,11 +36,7 @@ private:
Icon *iconBack; Icon *iconBack;
Icon *iconPlatform; Icon *iconPlatform;
#if defined(_WIN32) static TlsKey tlsIdx;
static DWORD tlsIdx;
#else
static pthread_key_t tlsIdx;
#endif
// 4J - was just a static but implemented with TLS for our version // 4J - was just a static but implemented with TLS for our version
static bool ignoreUpdate(); static bool ignoreUpdate();
static void ignoreUpdate(bool set); static void ignoreUpdate(bool set);
+4 -4
View File
@@ -12,12 +12,12 @@
namespace namespace
{ {
#if defined(_WIN32) #if defined(_WIN32)
inline void *TheEndPortalTlsGetValue(DWORD key) inline void *TheEndPortalTlsGetValue(TheEndPortal::TlsKey key)
{ {
return TlsGetValue(key); return TlsGetValue(key);
} }
inline void TheEndPortalTlsSetValue(DWORD key, void *value) inline void TheEndPortalTlsSetValue(TheEndPortal::TlsKey key, void *value)
{ {
TlsSetValue(key, value); TlsSetValue(key, value);
} }
@@ -42,9 +42,9 @@ namespace
} }
#if defined(_WIN32) #if defined(_WIN32)
DWORD TheEndPortal::tlsIdx = TlsAlloc(); TheEndPortal::TlsKey TheEndPortal::tlsIdx = TlsAlloc();
#else #else
pthread_key_t TheEndPortal::tlsIdx = CreateTheEndPortalTlsKey(); TheEndPortal::TlsKey TheEndPortal::tlsIdx = CreateTheEndPortalTlsKey();
#endif #endif
// 4J - allowAnywhere is a static in java, implementing as TLS here to make thread safe // 4J - allowAnywhere is a static in java, implementing as TLS here to make thread safe
+5 -2
View File
@@ -1,5 +1,6 @@
#pragma once #pragma once
#include "TileEntities/EntityTile.h" #include "TileEntities/EntityTile.h"
#include <cstdint>
#if !defined(_WIN32) #if !defined(_WIN32)
#include <pthread.h> #include <pthread.h>
@@ -9,10 +10,12 @@ class TheEndPortal : public EntityTile
{ {
public: public:
#if defined(_WIN32) #if defined(_WIN32)
static DWORD tlsIdx; using TlsKey = std::uint32_t;
#else #else
static pthread_key_t tlsIdx; using TlsKey = pthread_key_t;
#endif #endif
static TlsKey tlsIdx;
// 4J - was just a static but implemented with TLS for our version // 4J - was just a static but implemented with TLS for our version
static bool allowAnywhere(); static bool allowAnywhere();
static void allowAnywhere(bool set); static void allowAnywhere(bool set);
+4 -5
View File
@@ -19,12 +19,12 @@
namespace namespace
{ {
#if defined(_WIN32) #if defined(_WIN32)
inline void *TileTlsGetValue(DWORD key) inline void *TileTlsGetValue(Tile::TlsKey key)
{ {
return TlsGetValue(key); return TlsGetValue(key);
} }
inline void TileTlsSetValue(DWORD key, void *value) inline void TileTlsSetValue(Tile::TlsKey key, void *value)
{ {
TlsSetValue(key, value); TlsSetValue(key, value);
} }
@@ -235,9 +235,9 @@ Tile *Tile::stairs_quartz = NULL;
Tile *Tile::woolCarpet = NULL; Tile *Tile::woolCarpet = NULL;
#if defined(_WIN32) #if defined(_WIN32)
DWORD Tile::tlsIdxShape = TlsAlloc(); Tile::TlsKey Tile::tlsIdxShape = TlsAlloc();
#else #else
pthread_key_t Tile::tlsIdxShape = CreateTileTlsKey(); Tile::TlsKey Tile::tlsIdxShape = CreateTileTlsKey();
#endif #endif
Tile::ThreadStorage::ThreadStorage() Tile::ThreadStorage::ThreadStorage()
@@ -1667,4 +1667,3 @@ const int Tile::quartzBlock_Id;
const int Tile::stairs_quartz_Id; const int Tile::stairs_quartz_Id;
const int Tile::woolCarpet_Id; const int Tile::woolCarpet_Id;
#endif #endif
+9 -5
View File
@@ -3,6 +3,7 @@
#include "../Util/Vec3.h" #include "../Util/Vec3.h"
#include "../Util/Definitions.h" #include "../Util/Definitions.h"
#include "../Util/SoundTypes.h" #include "../Util/SoundTypes.h"
#include <cstdint>
#if !defined(_WIN32) #if !defined(_WIN32)
#include <pthread.h> #include <pthread.h>
#endif #endif
@@ -49,6 +50,13 @@ class Tile
friend class ChunkRebuildData; friend class ChunkRebuildData;
friend class WallTile; friend class WallTile;
public:
#if defined(_WIN32)
using TlsKey = std::uint32_t;
#else
using TlsKey = pthread_key_t;
#endif
protected: protected:
// 4J added so we can have separate shapes for different threads // 4J added so we can have separate shapes for different threads
class ThreadStorage class ThreadStorage
@@ -58,11 +66,7 @@ protected:
int tileId; int tileId;
ThreadStorage(); ThreadStorage();
}; };
#if defined(_WIN32) static TlsKey tlsIdxShape;
static DWORD tlsIdxShape;
#else
static pthread_key_t tlsIdxShape;
#endif
public: public:
// Each new thread that needs to use Vec3 pools will need to call one of the following 2 functions, to either create its own // Each new thread that needs to use Vec3 pools will need to call one of the following 2 functions, to either create its own
// local storage, or share the default storage already allocated by the main thread // local storage, or share the default storage already allocated by the main thread
+4 -4
View File
@@ -26,12 +26,12 @@
namespace namespace
{ {
#if defined(_WIN32) #if defined(_WIN32)
inline void *EntityTlsGetValue(DWORD key) inline void *EntityTlsGetValue(Entity::TlsKey key)
{ {
return TlsGetValue(key); return TlsGetValue(key);
} }
inline void EntityTlsSetValue(DWORD key, void *value) inline void EntityTlsSetValue(Entity::TlsKey key, void *value)
{ {
TlsSetValue(key, value); TlsSetValue(key, value);
} }
@@ -59,9 +59,9 @@ namespace
int Entity::entityCounter = 2048; // 4J - changed initialiser to 2048, as we are using range 0 - 2047 as special unique smaller ids for things that need network tracked int Entity::entityCounter = 2048; // 4J - changed initialiser to 2048, as we are using range 0 - 2047 as special unique smaller ids for things that need network tracked
#if defined(_WIN32) #if defined(_WIN32)
DWORD Entity::tlsIdx = TlsAlloc(); Entity::TlsKey Entity::tlsIdx = TlsAlloc();
#else #else
pthread_key_t Entity::tlsIdx = CreateEntityTlsKey(); Entity::TlsKey Entity::tlsIdx = CreateEntityTlsKey();
#endif #endif
// 4J - added getSmallId & freeSmallId methods // 4J - added getSmallId & freeSmallId methods
+8 -5
View File
@@ -5,6 +5,7 @@
#include "../IO/NBT/FloatTag.h" #include "../IO/NBT/FloatTag.h"
#include "../Util/Vec3.h" #include "../Util/Vec3.h"
#include "../Util/Definitions.h" #include "../Util/Definitions.h"
#include <cstdint>
#if !defined(_WIN32) #if !defined(_WIN32)
#include <pthread.h> #include <pthread.h>
#endif #endif
@@ -38,6 +39,12 @@ class Entity : public std::enable_shared_from_this<Entity>
{ {
friend class Gui; // 4J Stu - Added to be able to access the shared flag functions and constants, without making them publicly available to everything friend class Gui; // 4J Stu - Added to be able to access the shared flag functions and constants, without making them publicly available to everything
public: public:
#if defined(_WIN32)
using TlsKey = std::uint32_t;
#else
using TlsKey = pthread_key_t;
#endif
// 4J-PB - added to replace (e instanceof Type), avoiding dynamic casts // 4J-PB - added to replace (e instanceof Type), avoiding dynamic casts
virtual eINSTANCEOF GetType() = 0; virtual eINSTANCEOF GetType() = 0;
@@ -368,11 +375,7 @@ private:
static int extraWanderIds[EXTRA_WANDER_MAX]; static int extraWanderIds[EXTRA_WANDER_MAX];
static int extraWanderCount; static int extraWanderCount;
static int extraWanderTicks; static int extraWanderTicks;
#if defined(_WIN32) static TlsKey tlsIdx;
static DWORD tlsIdx;
#else
static pthread_key_t tlsIdx;
#endif
public: public:
static void tickExtraWandering(); static void tickExtraWandering();
static void countFlagsForPIX(); static void countFlagsForPIX();
+6 -6
View File
@@ -47,12 +47,12 @@
namespace namespace
{ {
#if defined(_WIN32) #if defined(_WIN32)
inline void *LevelTlsGetValue(DWORD key) inline void *LevelTlsGetValue(Level::TlsKey key)
{ {
return TlsGetValue(key); return TlsGetValue(key);
} }
inline void LevelTlsSetValue(DWORD key, void *value) inline void LevelTlsSetValue(Level::TlsKey key, void *value)
{ {
TlsSetValue(key, value); TlsSetValue(key, value);
} }
@@ -77,11 +77,11 @@ namespace
} }
#if defined(_WIN32) #if defined(_WIN32)
DWORD Level::tlsIdx = TlsAlloc(); Level::TlsKey Level::tlsIdx = TlsAlloc();
DWORD Level::tlsIdxLightCache = TlsAlloc(); Level::TlsKey Level::tlsIdxLightCache = TlsAlloc();
#else #else
pthread_key_t Level::tlsIdx = CreateLevelTlsKey(); Level::TlsKey Level::tlsIdx = CreateLevelTlsKey();
pthread_key_t Level::tlsIdxLightCache = CreateLevelTlsKey(); Level::TlsKey Level::tlsIdxLightCache = CreateLevelTlsKey();
#endif #endif
// 4J : WESTY : Added for time played stats. // 4J : WESTY : Added for time played stats.
+9 -7
View File
@@ -9,6 +9,7 @@
#include "../Util/ParticleTypes.h" #include "../Util/ParticleTypes.h"
#include "../WorldGen/Biomes/Biome.h" #include "../WorldGen/Biomes/Biome.h"
#include "../Util/C4JThread.h" #include "../Util/C4JThread.h"
#include <cstdint>
#if !defined(_WIN32) #if !defined(_WIN32)
#include <pthread.h> #include <pthread.h>
#endif #endif
@@ -48,6 +49,12 @@ class VillageSiege;
class Level : public LevelSource class Level : public LevelSource
{ {
public: public:
#if defined(_WIN32)
using TlsKey = std::uint32_t;
#else
using TlsKey = pthread_key_t;
#endif
static const int MAX_TICK_TILES_PER_TICK = 1000; static const int MAX_TICK_TILES_PER_TICK = 1000;
// 4J Added // 4J Added
@@ -80,13 +87,8 @@ public:
int seaLevel; int seaLevel;
// 4J - added, making instaTick flag use TLS so we can set it in the chunk rebuilding thread without upsetting the main game thread // 4J - added, making instaTick flag use TLS so we can set it in the chunk rebuilding thread without upsetting the main game thread
#if defined(_WIN32) static TlsKey tlsIdx;
static DWORD tlsIdx; static TlsKey tlsIdxLightCache;
static DWORD tlsIdxLightCache;
#else
static pthread_key_t tlsIdx;
static pthread_key_t tlsIdxLightCache;
#endif
static void enableLightingCache(); static void enableLightingCache();
static void destroyLightingCache(); static void destroyLightingCache();
static bool getCacheTestEnabled(); static bool getCacheTestEnabled();
@@ -11,18 +11,18 @@
#if defined(_WIN32) #if defined(_WIN32)
namespace namespace
{ {
inline void *OldChunkStorageTlsGetValue(DWORD key) inline void *OldChunkStorageTlsGetValue(OldChunkStorage::TlsKey key)
{ {
return TlsGetValue(key); return TlsGetValue(key);
} }
inline void OldChunkStorageTlsSetValue(DWORD key, void *value) inline void OldChunkStorageTlsSetValue(OldChunkStorage::TlsKey key, void *value)
{ {
TlsSetValue(key, value); TlsSetValue(key, value);
} }
} }
DWORD OldChunkStorage::tlsIdx = TlsAlloc(); OldChunkStorage::TlsKey OldChunkStorage::tlsIdx = TlsAlloc();
#else #else
namespace namespace
{ {
@@ -45,7 +45,7 @@ namespace
} }
} }
pthread_key_t OldChunkStorage::tlsIdx = CreateOldChunkStorageTlsKey(); OldChunkStorage::TlsKey OldChunkStorage::tlsIdx = CreateOldChunkStorageTlsKey();
#endif #endif
OldChunkStorage::ThreadStorage *OldChunkStorage::tlsDefault = NULL; OldChunkStorage::ThreadStorage *OldChunkStorage::tlsDefault = NULL;
@@ -4,6 +4,7 @@
#include "../../IO/Files/File.h" #include "../../IO/Files/File.h"
#include "../../IO/NBT/CompoundTag.h" #include "../../IO/NBT/CompoundTag.h"
#include "../../Headers/com.mojang.nbt.h" #include "../../Headers/com.mojang.nbt.h"
#include <cstdint>
#if !defined(_WIN32) #if !defined(_WIN32)
#include <pthread.h> #include <pthread.h>
#endif #endif
@@ -12,6 +13,13 @@ class Level;
class OldChunkStorage : public ChunkStorage class OldChunkStorage : public ChunkStorage
{ {
public:
#if defined(_WIN32)
using TlsKey = std::uint32_t;
#else
using TlsKey = pthread_key_t;
#endif
private: private:
// 4J added so we can have separate storage arrays for different threads // 4J added so we can have separate storage arrays for different threads
class ThreadStorage class ThreadStorage
@@ -25,11 +33,7 @@ private:
ThreadStorage(); ThreadStorage();
~ThreadStorage(); ~ThreadStorage();
}; };
#if defined(_WIN32) static TlsKey tlsIdx;
static DWORD tlsIdx;
#else
static pthread_key_t tlsIdx;
#endif
static ThreadStorage *tlsDefault; static ThreadStorage *tlsDefault;
public: public:
// Each new thread that needs to use Compression will need to call one of the following 2 functions, to either create its own // Each new thread that needs to use Compression will need to call one of the following 2 functions, to either create its own