mirror of
https://git.huckle.dev/Huckles-Minecraft-Archive/4jcraft.git
synced 2026-07-18 23:08:09 +00:00
refactor: switch to thread_local in Chunk, PistonBaseTile, TheEndPortalTile, Compression
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user