tinycc/tests/tests2/145_winarm64_interlocked.c
Mounir IDRASSI 3b1fe97a59 win32: define arm64 Interlocked helpers in winnt.h
Move the TinyCC/Windows ARM64 Interlocked workaround from the semlock call site into the bundled WinAPI header. This keeps tcc.h using the normal Interlocked API while avoiding unresolved Interlocked imports when tcc -run self-compiles on Windows ARM64.

Update lib/bt-exe.c as well so its ARM64 runtime object does not define a second InterlockedExchange fallback now provided by winnt.h.
2026-05-23 22:39:17 +09:00

36 lines
1.4 KiB
C

#include <stdio.h>
#include <windows.h>
#define PTR(x) ((PVOID)(ULONG_PTR)(x))
#define CHECK(name, expr) printf("%s: %s\n", name, (expr) ? "yes" : "no")
int main(void)
{
PVOID volatile slot = PTR(0x1111222233334444ULL);
PVOID old;
old = InterlockedExchangePointer(&slot, PTR(0x5555666677778888ULL));
CHECK("exchange old", old == PTR(0x1111222233334444ULL));
CHECK("exchange stored", slot == PTR(0x5555666677778888ULL));
old = InterlockedCompareExchangePointer(&slot,
PTR(0x9999aaaabbbbccccULL),
PTR(0x5555666677778888ULL));
CHECK("compare old", old == PTR(0x5555666677778888ULL));
CHECK("compare stored", slot == PTR(0x9999aaaabbbbccccULL));
old = InterlockedCompareExchangePointerAcquire(&slot,
PTR(0xdddd111122223333ULL),
PTR(0x0123456789abcdefULL));
CHECK("acquire old", old == PTR(0x9999aaaabbbbccccULL));
CHECK("acquire stored", slot == PTR(0x9999aaaabbbbccccULL));
old = InterlockedCompareExchangePointerRelease(&slot,
PTR(0xdddd111122223333ULL),
PTR(0x9999aaaabbbbccccULL));
CHECK("release old", old == PTR(0x9999aaaabbbbccccULL));
CHECK("release stored", slot == PTR(0xdddd111122223333ULL));
return 0;
}