2022-04-20 16:56:53 +00:00
|
|
|
#ifndef COSMOPOLITAN_LIBC_INTRIN_ONCE_H_
|
|
|
|
#define COSMOPOLITAN_LIBC_INTRIN_ONCE_H_
|
|
|
|
#include "libc/intrin/spinlock.h"
|
|
|
|
|
2022-09-05 15:26:03 +00:00
|
|
|
/* TODO(jart): DELETE */
|
|
|
|
|
2022-06-16 16:06:09 +00:00
|
|
|
#define _once(x) \
|
|
|
|
({ \
|
|
|
|
typeof(x) oncerc; \
|
|
|
|
static bool once; \
|
|
|
|
static typeof(oncerc) onceresult; \
|
|
|
|
_Alignas(64) static char oncelock; \
|
|
|
|
_spinlock(&oncelock); \
|
|
|
|
if (once) { \
|
|
|
|
oncerc = onceresult; \
|
|
|
|
} else { \
|
|
|
|
oncerc = onceresult = x; \
|
|
|
|
} \
|
|
|
|
_spunlock(&oncelock); \
|
|
|
|
oncerc; \
|
2022-04-20 16:56:53 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
#endif /* COSMOPOLITAN_LIBC_INTRIN_ONCE_H_ */
|