Add InterlockedCompareExchange (#85)

This commit is contained in:
rjkiv 2025-07-27 01:29:38 -07:00 committed by GitHub
parent 8bd112f0e4
commit 78f4d534df
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -2228,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 };
@ -2481,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;