mirror of
https://github.com/wiiu-env/wut.git
synced 2024-12-14 07:41:50 +01:00
24 lines
756 B
C++
24 lines
756 B
C++
|
#include "include/bits/gthr-default.h"
|
||
|
|
||
|
int
|
||
|
__gthread_once (__gthread_once_t *__once, void (*__func) (void))
|
||
|
{
|
||
|
uint32_t value = 0;
|
||
|
|
||
|
if (OSCompareAndSwapAtomicEx(__once,
|
||
|
__GTHREAD_ONCE_VALUE_INIT,
|
||
|
__GTHREAD_ONCE_VALUE_STARTED,
|
||
|
&value)) {
|
||
|
__func();
|
||
|
OSCompareAndSwapAtomic(__once,
|
||
|
__GTHREAD_ONCE_VALUE_STARTED,
|
||
|
__GTHREAD_ONCE_VALUE_DONE);
|
||
|
} else if (value != __GTHREAD_ONCE_VALUE_DONE) {
|
||
|
while (!OSCompareAndSwapAtomic(__once,
|
||
|
__GTHREAD_ONCE_VALUE_DONE,
|
||
|
__GTHREAD_ONCE_VALUE_DONE));
|
||
|
}
|
||
|
|
||
|
return 0;
|
||
|
}
|