mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-01-31 19:43:32 +00:00
7838edae88
The greenbean web server now works nearly perfectly on Windows with over 1000 threads. But some synchronization issues still remain which prevent us from going over nine thousand.
21 lines
729 B
C
21 lines
729 B
C
#ifndef COSMOPOLITAN_LIBC_INTRIN_ONCE_H_
|
|
#define COSMOPOLITAN_LIBC_INTRIN_ONCE_H_
|
|
#include "libc/intrin/spinlock.h"
|
|
|
|
#define _once(x) \
|
|
({ \
|
|
typeof(x) oncerc; \
|
|
static bool once; \
|
|
static typeof(oncerc) onceresult; \
|
|
_Alignas(64) static int oncelock; \
|
|
_spinlock(&oncelock); \
|
|
if (once) { \
|
|
oncerc = onceresult; \
|
|
} else { \
|
|
oncerc = onceresult = x; \
|
|
} \
|
|
_spunlock(&oncelock); \
|
|
oncerc; \
|
|
})
|
|
|
|
#endif /* COSMOPOLITAN_LIBC_INTRIN_ONCE_H_ */
|