feat: stub critical sections on top of pthread recursive mutexes

This commit is contained in:
Tropical 2026-03-02 19:25:37 -06:00
parent c4b25bc622
commit 065ffff071
3 changed files with 41 additions and 48 deletions

View file

@ -2,7 +2,7 @@
#include "net.minecraft.world.level.levelgen.h"
#include "net.minecraft.world.level.h"
#include "net.minecraft.world.level.storage.h"
#include "dimension.h"
#include "Dimension.h"
#include "BiomeSource.h"
#include "FixedBiomeSource.h"
#include "OldChunkStorage.h"

View file

@ -86,6 +86,44 @@ typedef float FLOAT;
#define TLS_OUT_OF_INDEXES ((DWORD)0xFFFFFFFF)
typedef pthread_mutex_t RTL_CRITICAL_SECTION;
typedef pthread_mutex_t* PRTL_CRITICAL_SECTION;
typedef RTL_CRITICAL_SECTION CRITICAL_SECTION;
typedef PRTL_CRITICAL_SECTION PCRITICAL_SECTION;
typedef PRTL_CRITICAL_SECTION LPCRITICAL_SECTION;
void InitializeCriticalSection(PRTL_CRITICAL_SECTION CriticalSection) {
pthread_mutexattr_t attr;
int ret;
pthread_mutexattr_init(&attr);
pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);
pthread_mutex_init(CriticalSection, &attr);
pthread_mutexattr_destroy(&attr);
}
void InitializeCriticalSectionAndSpinCount(PRTL_CRITICAL_SECTION CriticalSection, ULONG SpinCount) {
// no spin count required because we use a recursive mutex
InitializeCriticalSection(CriticalSection);
}
void DeleteCriticalSection(PRTL_CRITICAL_SECTION CriticalSection) {
pthread_mutex_destroy(CriticalSection);
}
void EnterCriticalSection(PRTL_CRITICAL_SECTION CriticalSection) {
pthread_mutex_lock(CriticalSection);
}
void LeaveCriticalSection(PRTL_CRITICAL_SECTION CriticalSection) {
pthread_mutex_unlock(CriticalSection);
}
ULONG TryEnterCriticalSection(PRTL_CRITICAL_SECTION CriticalSection) {
return pthread_mutex_trylock(CriticalSection) == 0;
}
// https://learn.microsoft.com/en-us/windows/win32/api/processthreadsapi/nf-processthreadsapi-tlsalloc
DWORD TlsAlloc(VOID) {
pthread_key_t key;
@ -119,8 +157,8 @@ BOOL TlsSetValue(DWORD dwTlsIndex, LPVOID lpTlsValue)
// https://learn.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-globalmemorystatus
VOID GlobalMemoryStatus(LPMEMORYSTATUS lpBuffer)
{
// TODO: Parse /proc/meminfo and set based on that. Probably will also need another different
// codepath for macOS too.
// TODO: Parse /proc/meminfo and set lpBuffer based on that. Probably will also need another
// different codepath for macOS too.
}
DWORD GetLastError(VOID)

View file

@ -22,51 +22,6 @@ const int XUSER_MAX_COUNT = 4;
const int MINECRAFT_NET_MAX_PLAYERS = 8;
#endif
#if defined(__linux__)
typedef struct _RTL_CRITICAL_SECTION {
// //
// // The following field is used for blocking when there is contention for
// // the resource
// //
//
union {
ULONG_PTR RawEvent[4];
} Synchronization;
//
// //
// // The following three fields control entering and exiting the critical
// // section for the resource
// //
//
LONG LockCount;
LONG RecursionCount;
HANDLE OwningThread;
} RTL_CRITICAL_SECTION, *PRTL_CRITICAL_SECTION;
typedef RTL_CRITICAL_SECTION CRITICAL_SECTION;
inline void InitializeCriticalSection(CRITICAL_SECTION* stubEnterCS)
{
}
inline void InitializeCriticalSectionAndSpinCount(CRITICAL_SECTION* CriticalSection, ULONG SpinCount)
{
}
inline void DeleteCriticalSection(CRITICAL_SECTION* stubEnterCS)
{
}
inline void EnterCriticalSection(CRITICAL_SECTION* stubEnterCS)
{
}
inline void LeaveCriticalSection( CRITICAL_SECTION* stubEnterCS)
{
}
#endif // __linux__
#ifdef __ORBIS__
#include <net.h>
#include <np/np_npid.h>