91 #ifndef V8_LAZY_INSTANCE_H_
92 #define V8_LAZY_INSTANCE_H_
99 #define LAZY_STATIC_INSTANCE_INITIALIZER { V8_ONCE_INIT, {} }
100 #define LAZY_DYNAMIC_INSTANCE_INITIALIZER { V8_ONCE_INIT, 0 }
103 #define LAZY_INSTANCE_INITIALIZER LAZY_STATIC_INSTANCE_INITIALIZER
106 template <
typename T>
116 #if defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ > 2))
117 #define LAZY_ALIGN(x) __attribute__((aligned(__alignof__(x))))
119 #define LAZY_ALIGN(x)
122 template <
typename T>
127 return reinterpret_cast<T*
>(storage);
130 template <
typename ConstructTrait>
139 template <
typename T>
147 template <
typename CreateTrait>
149 *storage = CreateTrait::Create();
154 template <
typename T>
158 new(allocated_ptr)
T();
163 template <
typename T>
172 template <
typename Function,
typename Storage>
181 template <
typename Function,
typename Storage>
192 template <
typename T,
typename AllocationTrait,
typename CreateTrait,
193 typename InitOnceTrait,
typename DestroyTrait >
200 AllocationTrait::template InitStorageUsingTrait<CreateTrait>(storage);
208 reinterpret_cast<void(*)(
void*)
>(&InitInstance),
209 reinterpret_cast<void*>(&
storage_));
215 return AllocationTrait::MutableInstance(&
storage_);
220 return *AllocationTrait::MutableInstance(&
storage_);
231 template <
typename T,
237 CreateTrait, InitOnceTrait, DestroyTrait>
type;
241 template <
typename T,
252 template <
typename T,
258 CreateTrait, InitOnceTrait, DestroyTrait>
type;
263 #endif // V8_LAZY_INSTANCE_H_
static T * MutableInstance(StorageType *storage)
static void Construct(T *allocated_ptr)
AllocationTrait::StorageType StorageType
void CallOnce(OnceType *once, NoArgFunction init_func)
static void InitStorageUsingTrait(StorageType *storage)
LazyInstanceImpl< T, StaticallyAllocatedInstanceTrait< T >, CreateTrait, InitOnceTrait, DestroyTrait > type
static void InitStorageUsingTrait(StorageType *storage)
char StorageType[sizeof(T)] LAZY_ALIGN(T)
static void Init(OnceType *once, Function function, Storage storage)
#define T(name, string, precedence)
static T * MutableInstance(StorageType *storage)
static void Init(OnceType *once, Function function, Storage storage)
LazyStaticInstance< T, CreateTrait, InitOnceTrait, DestroyTrait >::type type
LazyInstanceImpl< T, DynamicallyAllocatedInstanceTrait< T >, CreateTrait, InitOnceTrait, DestroyTrait > type