From d88a4c953012740d953215019a3a83fcc197bd2e Mon Sep 17 00:00:00 2001 From: rjkiv <76180273+rjkiv@users.noreply.github.com> Date: Sat, 26 Jul 2025 21:26:14 -0700 Subject: [PATCH] un-atomicize --- dll/kernel32.cpp | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/dll/kernel32.cpp b/dll/kernel32.cpp index cf8b8ce..e030bdd 100644 --- a/dll/kernel32.cpp +++ b/dll/kernel32.cpp @@ -87,10 +87,6 @@ namespace kernel32 { } } - LONG InterlockedCompareExchange(volatile LONG* destination, LONG exchange, LONG comperand){ - return __sync_val_compare_and_swap(destination, comperand, exchange); - } - int64_t getFileSize(void* hFile) { FILE *fp = files::fpFromHandle(hFile); struct stat64 st; @@ -2232,6 +2228,15 @@ namespace kernel32 { return initial; } + LONG WIN_FUNC InterlockedCompareExchange(volatile LONG* destination, LONG exchange, LONG comperand){ + LONG original = *destination; + if (original == comperand) { + *destination = exchange; + } + return original; + // return __sync_val_compare_and_swap(destination, comperand, exchange); if we want to maintain the atomic behavior + } + // These are effectively a copy/paste of the Tls* functions enum { MAX_FLS_VALUES = 100 }; static bool flsValuesUsed[MAX_FLS_VALUES] = { false }; @@ -2485,6 +2490,7 @@ static void *resolveByName(const char *name) { if (strcmp(name, "InterlockedIncrement") == 0) return (void *) kernel32::InterlockedIncrement; if (strcmp(name, "InterlockedDecrement") == 0) return (void *) kernel32::InterlockedDecrement; if (strcmp(name, "InterlockedExchange") == 0) return (void *) kernel32::InterlockedExchange; + if (strcmp(name, "InterlockedCompareExchange") == 0) return (void*) kernel32::InterlockedCompareExchange; // fibersapi.h if (strcmp(name, "FlsAlloc") == 0) return (void *) kernel32::FlsAlloc;