wut/libraries/wutstdc++/wut_gthread_once.cpp
GaryOderNichts 2c98cc91aa
Some checks failed
C/C++ CI / ubuntu-latest (push) Has been cancelled
Run clang-format
`find . -regex '.*\.\(cpp\|hpp\|cu\|cuh\|c\|h\)' -exec clang-format -style=file -i {} \;`
2025-06-05 11:06:04 +01:00

24 lines
628 B
C++

#include "wut_gthread.h"
int
__wut_once(__wut_once_t *once,
void (*func)(void))
{
uint32_t value = 0;
if (OSCompareAndSwapAtomicEx(once,
__WUT_ONCE_VALUE_INIT,
__WUT_ONCE_VALUE_STARTED,
&value)) {
func();
OSSwapAtomic(once,
__WUT_ONCE_VALUE_DONE);
} else if (value != __WUT_ONCE_VALUE_DONE) {
while (!OSCompareAndSwapAtomic(once,
__WUT_ONCE_VALUE_DONE,
__WUT_ONCE_VALUE_DONE));
}
return 0;
}