refactor: switch to thread_local in Chunk, PistonBaseTile, TheEndPortalTile, Compression

This commit is contained in:
Tropical
2026-03-25 14:41:08 -05:00
parent 4a1fb94600
commit 9ff2fb4fef
8 changed files with 29 additions and 103 deletions

View File

@@ -9,47 +9,16 @@
#include "../Headers/net.minecraft.world.h"
#include <cstdint>
namespace {
#if defined(_WIN32)
inline void* TheEndPortalTlsGetValue(TheEndPortal::TlsKey key) {
return TlsGetValue(key);
}
inline void TheEndPortalTlsSetValue(TheEndPortal::TlsKey key, void* value) {
TlsSetValue(key, value);
}
#else
pthread_key_t CreateTheEndPortalTlsKey() {
pthread_key_t key;
pthread_key_create(&key, NULL);
return key;
}
inline void* TheEndPortalTlsGetValue(pthread_key_t key) {
return pthread_getspecific(key);
}
inline void TheEndPortalTlsSetValue(pthread_key_t key, void* value) {
pthread_setspecific(key, value);
}
#endif
} // namespace
#if defined(_WIN32)
TheEndPortal::TlsKey TheEndPortal::tlsIdx = TlsAlloc();
#else
TheEndPortal::TlsKey TheEndPortal::tlsIdx = CreateTheEndPortalTlsKey();
#endif
thread_local bool TheEndPortal::m_threadAllowAnywhere = false;
// 4J - allowAnywhere is a static in java, implementing as TLS here to make
// thread safe
bool TheEndPortal::allowAnywhere() {
return TheEndPortalTlsGetValue(tlsIdx) != NULL;
return m_threadAllowAnywhere;
}
void TheEndPortal::allowAnywhere(bool set) {
TheEndPortalTlsSetValue(
tlsIdx, reinterpret_cast<void*>(static_cast<intptr_t>(set ? 1 : 0)));
m_threadAllowAnywhere = set;
}
TheEndPortal::TheEndPortal(int id, Material* material)