52 #ifndef V8_BASE_ONCE_H_ 53 #define V8_BASE_ONCE_H_ 58 #include "src/base/atomicops.h" 59 #include "src/base/base-export.h" 64 typedef AtomicWord OnceType;
66 #define V8_ONCE_INIT 0 68 #define V8_DECLARE_ONCE(NAME) ::v8::base::OnceType NAME 71 ONCE_STATE_UNINITIALIZED = 0,
72 ONCE_STATE_EXECUTING_FUNCTION = 1,
76 typedef void (*NoArgFunction)();
77 typedef void (*PointerArgFunction)(
void* arg);
81 typedef void (*
type)(
T);
84 V8_BASE_EXPORT
void CallOnceImpl(OnceType* once,
85 std::function<
void()> init_func);
87 inline void CallOnce(OnceType* once, NoArgFunction init_func) {
88 if (Acquire_Load(once) != ONCE_STATE_DONE) {
89 CallOnceImpl(once, init_func);
94 template <
typename Arg>
95 inline void CallOnce(OnceType* once,
96 typename OneArgFunction<Arg*>::type init_func, Arg* arg) {
97 if (Acquire_Load(once) != ONCE_STATE_DONE) {
98 CallOnceImpl(once, [=]() { init_func(arg); });
105 #endif // V8_BASE_ONCE_H_