5#ifndef V8_BASE_LAZY_INSTANCE_H_
6#define V8_BASE_LAZY_INSTANCE_H_
79#define LAZY_STATIC_INSTANCE_INITIALIZER { V8_ONCE_INIT, { {} } }
80#define LAZY_DYNAMIC_INSTANCE_INITIALIZER { V8_ONCE_INIT, 0 }
83#define LAZY_INSTANCE_INITIALIZER LAZY_STATIC_INSTANCE_INITIALIZER
101 return reinterpret_cast<T*
>(storage);
104 template <
typename ConstructTrait>
106 ConstructTrait::Construct(storage);
120 template <
typename CreateTrait>
122 *storage = CreateTrait::Create();
130 static void Construct(
void* allocated_ptr) {
new (allocated_ptr)
T(); }
143 template <
typename Function,
typename Storage>
152 template <
typename Function,
typename Storage>
163template <
typename T,
typename AllocationTrait,
typename CreateTrait,
164 typename InitOnceTrait,
typename DestroyTrait >
172 AllocationTrait::template InitStorageUsingTrait<CreateTrait>(
183 return AllocationTrait::MutableInstance(&
storage_);
188 return *AllocationTrait::MutableInstance(&
storage_);
202 CreateTrait, InitOnceTrait, DestroyTrait>;
223 CreateTrait, InitOnceTrait, DestroyTrait>;
232 template <
typename... Args>
248#define DEFINE_LAZY_LEAKY_OBJECT_GETTER(T, FunctionName, ...) \
249 T* FunctionName() { \
250 static ::v8::base::LeakyObject<T> object{__VA_ARGS__}; \
251 return object.get(); \
LeakyObject & operator=(const LeakyObject &)=delete
LeakyObject(Args &&... args)
LeakyObject(const LeakyObject &)=delete
void CallOnce(OnceType *once, std::function< void()> init_func)
std::atomic< uint8_t > OnceType
V8_BASE_EXPORT int const char va_list args
@ ONCE_STATE_UNINITIALIZED
static void Construct(void *allocated_ptr)
static void InitStorageUsingTrait(StorageType *storage)
static T * MutableInstance(StorageType *storage)
typename AllocationTrait::AlignmentType AlignmentType
typename AllocationTrait::StorageType StorageType
static void InitInstance(void *storage)
typename LazyStaticInstance< T, CreateTrait, InitOnceTrait, DestroyTrait >::type type
static void Init(OnceType *once, Function function, Storage storage)
static void InitStorageUsingTrait(StorageType *storage)
char[sizeof(T)] StorageType
static T * MutableInstance(StorageType *storage)
static void Init(OnceType *once, Function function, Storage storage)