fix(linux): more shit

This commit is contained in:
Mohamed Ashraf authored and Anaël committed 2026-11-28 01:58:00 +01:00
1 parent 20278c2856
commit a0a35f3c0b
18 files changed
+267 -80

No files matched your search

+40 -9
View File
@@ -4,12 +4,20 @@
#include "../Minecraft.Client/Common/zlib/zlib.h"
#endif
#if defined(__linux__)
#include "../Minecraft.Client/Common/zlib/zlib.h"
#include <pthread.h> // TLS shit
#endif // __linux__
#if defined __PSVITA__
#include "../Minecraft.Client/PSVita/PSVitaExtras/zlib.h"
#elif defined __PS3__
#include "../Minecraft.Client/PS3/PS3Extras/EdgeZLib.h"
#endif //__PS3__
#if defined(__linux__)
#define S_OK 0
#endif // __linux__
DWORD Compression::tlsIdx = 0;
Compression::ThreadStorage *Compression::tlsDefault = nullptr;
@@ -27,22 +35,40 @@ Compression::ThreadStorage::~ThreadStorage()
void Compression::CreateNewThreadStorage()
{
ThreadStorage *tls = new ThreadStorage();
if(tlsDefault == nullptr )
if (tlsDefault == nullptr)
{
tlsIdx = TlsAlloc();
#ifdef _WIN32
tlsIdx = TlsAlloc();
tlsDefault = tls;
#else
pthread_key_create(&tlsIdx, nullptr);
tlsDefault = tls;
#endif
}
#ifdef _WIN32
TlsSetValue(tlsIdx, tls);
#else
pthread_setspecific(tlsIdx, tls);
#endif
}
void Compression::UseDefaultThreadStorage()
{
TlsSetValue(tlsIdx, tlsDefault);
#ifdef _WIN32
TlsSetValue(tlsIdx, tlsDefault);
#else
pthread_setspecific(tlsIdx, tlsDefault);
#endif
}
void Compression::ReleaseThreadStorage()
{
#ifdef _WIN32
const ThreadStorage *tls = static_cast<ThreadStorage *>(TlsGetValue(tlsIdx));
#else // Linux
const ThreadStorage *tls = static_cast<ThreadStorage *>(pthread_getspecific(tlsIdx));
#endif // _WIN32
if( tls == tlsDefault ) return;
delete tls;
@@ -50,7 +76,12 @@ void Compression::ReleaseThreadStorage()
Compression *Compression::getCompression()
{
#ifdef _WIN32
const ThreadStorage *tls = static_cast<ThreadStorage *>(TlsGetValue(tlsIdx));
#else // Linux
const ThreadStorage *tls = static_cast<ThreadStorage *>(pthread_getspecific(tlsIdx));
#endif // _WIN32
if (!tls) {
return nullptr;
}
@@ -333,7 +364,7 @@ HRESULT Compression::DecompressLZXRLE(void *pDestination, unsigned int *pDestSiz
HRESULT Compression::DecompressRLE(void *pDestination, unsigned int *pDestSize, void *pSource, unsigned int SrcSize)
{
EnterCriticalSection(&rleDecompressLock);
//unsigned char *pucIn = (unsigned char *)rleDecompressBuf;
unsigned char *pucIn = static_cast<unsigned char *>(pSource);
const unsigned char *pucEnd = pucIn + SrcSize;
@@ -507,7 +538,7 @@ HRESULT Compression::DecompressWithType(void *pDestination, unsigned int *pDestS
#endif
case eCompressionType_PS3ZLIB:
#if (defined __ORBIS__ || defined __PSVITA__ || defined _DURANGO || defined _WIN64)
// Note that we're missing the normal zlib header and footer so we'll use inflate to
// Note that we're missing the normal zlib header and footer so we'll use inflate to
// decompress the payload and skip all the CRC checking, etc
if (pDestination != nullptr)
{
@@ -559,12 +590,12 @@ HRESULT Compression::DecompressWithType(void *pDestination, unsigned int *pDestS
return S_OK;
}
else break; // Cannot decompress when destination is nullptr
#else
#else
assert(0);
#endif
}
assert(false);
assert(false);
return -1;
}
@@ -594,8 +625,10 @@ Compression::Compression()
#endif
m_decompressType = m_localDecompressType;
#ifndef __linux__
InitializeCriticalSection(&rleCompressLock);
InitializeCriticalSection(&rleDecompressLock);
#endif // __linux__
}
Compression::~Compression()
@@ -634,5 +667,3 @@ void Compression::SetDecompressionType(ESavePlatform platform)
}
/*Compression gCompression;*/