OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // The LazyInstance<Type, Traits> class manages a single instance of Type, | 5 // The LazyInstance<Type, Traits> class manages a single instance of Type, |
6 // which will be lazily created on the first time it's accessed. This class is | 6 // which will be lazily created on the first time it's accessed. This class is |
7 // useful for places you would normally use a function-level static, but you | 7 // useful for places you would normally use a function-level static, but you |
8 // need to have guaranteed thread-safety. The Type constructor will only ever | 8 // need to have guaranteed thread-safety. The Type constructor will only ever |
9 // be called once, even if two threads are racing to create the object. Get() | 9 // be called once, even if two threads are racing to create the object. Get() |
10 // and Pointer() will always return the same, completely initialized instance. | 10 // and Pointer() will always return the same, completely initialized instance. |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
61 // - "Dynamic mode". In this mode, the instance is dynamically allocated and | 61 // - "Dynamic mode". In this mode, the instance is dynamically allocated and |
62 // constructed (using new) by default. This mode is useful if you have to | 62 // constructed (using new) by default. This mode is useful if you have to |
63 // deal with some code already allocating the instance for you (e.g. | 63 // deal with some code already allocating the instance for you (e.g. |
64 // OS::Mutex() which returns a new private OS-dependent subclass of Mutex). | 64 // OS::Mutex() which returns a new private OS-dependent subclass of Mutex). |
65 // The macro LAZY_DYNAMIC_INSTANCE_INITIALIZER must be used to initialize | 65 // The macro LAZY_DYNAMIC_INSTANCE_INITIALIZER must be used to initialize |
66 // dynamic lazy instances. | 66 // dynamic lazy instances. |
67 | 67 |
68 #ifndef V8_LAZY_INSTANCE_H_ | 68 #ifndef V8_LAZY_INSTANCE_H_ |
69 #define V8_LAZY_INSTANCE_H_ | 69 #define V8_LAZY_INSTANCE_H_ |
70 | 70 |
71 #include "base/macros.h" | 71 #include "src/base/macros.h" |
72 #include "once.h" | 72 #include "src/once.h" |
73 | 73 |
74 namespace v8 { | 74 namespace v8 { |
75 namespace internal { | 75 namespace internal { |
76 | 76 |
77 #define LAZY_STATIC_INSTANCE_INITIALIZER { V8_ONCE_INIT, { {} } } | 77 #define LAZY_STATIC_INSTANCE_INITIALIZER { V8_ONCE_INIT, { {} } } |
78 #define LAZY_DYNAMIC_INSTANCE_INITIALIZER { V8_ONCE_INIT, 0 } | 78 #define LAZY_DYNAMIC_INSTANCE_INITIALIZER { V8_ONCE_INIT, 0 } |
79 | 79 |
80 // Default to static mode. | 80 // Default to static mode. |
81 #define LAZY_INSTANCE_INITIALIZER LAZY_STATIC_INSTANCE_INITIALIZER | 81 #define LAZY_INSTANCE_INITIALIZER LAZY_STATIC_INSTANCE_INITIALIZER |
82 | 82 |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
228 typename InitOnceTrait = ThreadSafeInitOnceTrait, | 228 typename InitOnceTrait = ThreadSafeInitOnceTrait, |
229 typename DestroyTrait = LeakyInstanceTrait<T> > | 229 typename DestroyTrait = LeakyInstanceTrait<T> > |
230 struct LazyDynamicInstance { | 230 struct LazyDynamicInstance { |
231 typedef LazyInstanceImpl<T, DynamicallyAllocatedInstanceTrait<T>, | 231 typedef LazyInstanceImpl<T, DynamicallyAllocatedInstanceTrait<T>, |
232 CreateTrait, InitOnceTrait, DestroyTrait> type; | 232 CreateTrait, InitOnceTrait, DestroyTrait> type; |
233 }; | 233 }; |
234 | 234 |
235 } } // namespace v8::internal | 235 } } // namespace v8::internal |
236 | 236 |
237 #endif // V8_LAZY_INSTANCE_H_ | 237 #endif // V8_LAZY_INSTANCE_H_ |
OLD | NEW |