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
+6 -6
View File
@@ -47,12 +47,12 @@
namespace
{
#if defined(_WIN32)
inline void *LevelTlsGetValue(DWORD key)
inline void *LevelTlsGetValue(Level::TlsKey key)
{
return TlsGetValue(key);
}
inline void LevelTlsSetValue(DWORD key, void *value)
inline void LevelTlsSetValue(Level::TlsKey key, void *value)
{
TlsSetValue(key, value);
}
@@ -77,11 +77,11 @@ namespace
}
#if defined(_WIN32)
DWORD Level::tlsIdx = TlsAlloc();
DWORD Level::tlsIdxLightCache = TlsAlloc();
Level::TlsKey Level::tlsIdx = TlsAlloc();
Level::TlsKey Level::tlsIdxLightCache = TlsAlloc();
#else
pthread_key_t Level::tlsIdx = CreateLevelTlsKey();
pthread_key_t Level::tlsIdxLightCache = CreateLevelTlsKey();
Level::TlsKey Level::tlsIdx = CreateLevelTlsKey();
Level::TlsKey Level::tlsIdxLightCache = CreateLevelTlsKey();
#endif
// 4J : WESTY : Added for time played stats.
+9 -7
View File
@@ -9,6 +9,7 @@
#include "../Util/ParticleTypes.h"
#include "../WorldGen/Biomes/Biome.h"
#include "../Util/C4JThread.h"
#include <cstdint>
#if !defined(_WIN32)
#include <pthread.h>
#endif
@@ -48,6 +49,12 @@ class VillageSiege;
class Level : public LevelSource
{
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;
// 4J Added
@@ -80,13 +87,8 @@ public:
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
#if defined(_WIN32)
static DWORD tlsIdx;
static DWORD tlsIdxLightCache;
#else
static pthread_key_t tlsIdx;
static pthread_key_t tlsIdxLightCache;
#endif
static TlsKey tlsIdx;
static TlsKey tlsIdxLightCache;
static void enableLightingCache();
static void destroyLightingCache();
static bool getCacheTestEnabled();
@@ -11,18 +11,18 @@
#if defined(_WIN32)
namespace
{
inline void *OldChunkStorageTlsGetValue(DWORD key)
inline void *OldChunkStorageTlsGetValue(OldChunkStorage::TlsKey key)
{
return TlsGetValue(key);
}
inline void OldChunkStorageTlsSetValue(DWORD key, void *value)
inline void OldChunkStorageTlsSetValue(OldChunkStorage::TlsKey key, void *value)
{
TlsSetValue(key, value);
}
}
DWORD OldChunkStorage::tlsIdx = TlsAlloc();
OldChunkStorage::TlsKey OldChunkStorage::tlsIdx = TlsAlloc();
#else
namespace
{
@@ -45,7 +45,7 @@ namespace
}
}
pthread_key_t OldChunkStorage::tlsIdx = CreateOldChunkStorageTlsKey();
OldChunkStorage::TlsKey OldChunkStorage::tlsIdx = CreateOldChunkStorageTlsKey();
#endif
OldChunkStorage::ThreadStorage *OldChunkStorage::tlsDefault = NULL;
@@ -4,6 +4,7 @@
#include "../../IO/Files/File.h"
#include "../../IO/NBT/CompoundTag.h"
#include "../../Headers/com.mojang.nbt.h"
#include <cstdint>
#if !defined(_WIN32)
#include <pthread.h>
#endif
@@ -12,6 +13,13 @@ class Level;
class OldChunkStorage : public ChunkStorage
{
public:
#if defined(_WIN32)
using TlsKey = std::uint32_t;
#else
using TlsKey = pthread_key_t;
#endif
private:
// 4J added so we can have separate storage arrays for different threads
class ThreadStorage
@@ -25,11 +33,7 @@ private:
ThreadStorage();
~ThreadStorage();
};
#if defined(_WIN32)
static DWORD tlsIdx;
#else
static pthread_key_t tlsIdx;
#endif
static TlsKey tlsIdx;
static ThreadStorage *tlsDefault;
public:
// Each new thread that needs to use Compression will need to call one of the following 2 functions, to either create its own