diff options
author | Jean-Francois Mauguit <jfmauguit@mac.com> | 2024-09-24 09:03:25 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-09-24 09:03:25 -0400 |
commit | bab614c421ed7ae329d26bf028c4a3b1d2450f5a (patch) | |
tree | 12f17f78986871dd2cfb0a56e5e93b545c1ae0d0 /Src/replicant/nx/win/nxonce.c | |
parent | 4bde6044fddf053f31795b9eaccdd2a5a527d21f (diff) | |
parent | 20d28e80a5c861a9d5f449ea911ab75b4f37ad0d (diff) | |
download | winamp-bab614c421ed7ae329d26bf028c4a3b1d2450f5a.tar.gz |
Merge pull request #5 from WinampDesktop/community
Merge to main
Diffstat (limited to 'Src/replicant/nx/win/nxonce.c')
-rw-r--r-- | Src/replicant/nx/win/nxonce.c | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/Src/replicant/nx/win/nxonce.c b/Src/replicant/nx/win/nxonce.c new file mode 100644 index 00000000..293534f7 --- /dev/null +++ b/Src/replicant/nx/win/nxonce.c @@ -0,0 +1,43 @@ +#include "nxonce.h" +#include "foundation/error.h" +#if 0 && _WIN32_WINNT >= 0x600 + +void NXOnce(nx_once_t once, int (NX_ONCE_API *init_fn)(nx_once_t, void *, void **), void *param) +{ + InitOnceExecuteOnce(once, (PINIT_ONCE_FN)init_fn, param, 0); +} + +void NXOnceInit(nx_once_t once) +{ + InitOnceInitialize(once); +} +#else +/* this ONLY works because of the strict(ish) memory ordering of the AMD64/x86 processors. + Don't use this implementation for a processor that has loose memory ordering restriction (e.g. ARM, PowerPC) + see http://www.aristeia.com/Papers/DDJ_Jul_Aug_2004_revised.pdf + */ +void NXOnce(nx_once_t once, int (NX_ONCE_API *init_fn)(nx_once_t, void *, void **), void *param) +{ + if (once->status) + return; + + EnterCriticalSection(&once->critical_section); + if (once->status) + { + LeaveCriticalSection(&once->critical_section); + return; + } + + init_fn(once, param, 0); + // benski> not important for the x86, but on processors with weak memory-order on stores, once->status might set to 1 BEFORE all stores from init_fn complete! + once->status = 1; + LeaveCriticalSection(&once->critical_section); +} + +void NXOnceInit(nx_once_t once) +{ + once->status=0; + InitializeCriticalSection(&once->critical_section); +} + +#endif
\ No newline at end of file |