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

@@ -20,37 +20,7 @@ const std::wstring PistonBaseTile::INSIDE_TEX = L"piston_inner_top";
const float PistonBaseTile::PLATFORM_THICKNESS = 4.0f;
namespace {
#if defined(_WIN32)
inline void* PistonTlsGetValue(PistonBaseTile::TlsKey key) {
return TlsGetValue(key);
}
inline void PistonTlsSetValue(PistonBaseTile::TlsKey key, void* value) {
TlsSetValue(key, value);
}
#else
pthread_key_t CreatePistonTlsKey() {
pthread_key_t key;
pthread_key_create(&key, NULL);
return key;
}
inline void* PistonTlsGetValue(pthread_key_t key) {
return pthread_getspecific(key);
}
inline void PistonTlsSetValue(pthread_key_t key, void* value) {
pthread_setspecific(key, value);
}
#endif
} // namespace
#if defined(_WIN32)
PistonBaseTile::TlsKey PistonBaseTile::tlsIdx = TlsAlloc();
#else
PistonBaseTile::TlsKey PistonBaseTile::tlsIdx = CreatePistonTlsKey();
#endif
thread_local bool PistonBaseTile::m_threadIgnoreUpdate = false;
// 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
@@ -62,12 +32,11 @@ PistonBaseTile::TlsKey PistonBaseTile::tlsIdx = CreatePistonTlsKey();
// 4J - ignoreUpdate is a static in java, implementing as TLS here to make
// thread safe
bool PistonBaseTile::ignoreUpdate() {
return PistonTlsGetValue(tlsIdx) != NULL;
return m_threadIgnoreUpdate;
}
void PistonBaseTile::ignoreUpdate(bool set) {
PistonTlsSetValue(
tlsIdx, reinterpret_cast<void*>(static_cast<intptr_t>(set ? 1 : 0)));
m_threadIgnoreUpdate = set;
}
PistonBaseTile::PistonBaseTile(int id, bool isSticky)