| OLD | NEW |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // modification, are permitted provided that the following conditions are | 3 // found in the LICENSE file. |
| 4 // met: | |
| 5 // | |
| 6 // * Redistributions of source code must retain the above copyright | |
| 7 // notice, this list of conditions and the following disclaimer. | |
| 8 // * Redistributions in binary form must reproduce the above | |
| 9 // copyright notice, this list of conditions and the following | |
| 10 // disclaimer in the documentation and/or other materials provided | |
| 11 // with the distribution. | |
| 12 // * Neither the name of Google Inc. nor the names of its | |
| 13 // contributors may be used to endorse or promote products derived | |
| 14 // from this software without specific prior written permission. | |
| 15 // | |
| 16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
| 17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
| 18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | |
| 19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | |
| 20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
| 21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |
| 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |
| 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |
| 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
| 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
| 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
| 27 | 4 |
| 28 // The LazyInstance<Type, Traits> class manages a single instance of Type, | 5 // The LazyInstance<Type, Traits> class manages a single instance of Type, |
| 29 // 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 |
| 30 // 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 |
| 31 // 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 |
| 32 // 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() |
| 33 // and Pointer() will always return the same, completely initialized instance. | 10 // and Pointer() will always return the same, completely initialized instance. |
| 34 // | 11 // |
| 35 // LazyInstance is completely thread safe, assuming that you create it safely. | 12 // LazyInstance is completely thread safe, assuming that you create it safely. |
| 36 // The class was designed to be POD initialized, so it shouldn't require a | 13 // The class was designed to be POD initialized, so it shouldn't require a |
| (...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 251 typename InitOnceTrait = ThreadSafeInitOnceTrait, | 228 typename InitOnceTrait = ThreadSafeInitOnceTrait, |
| 252 typename DestroyTrait = LeakyInstanceTrait<T> > | 229 typename DestroyTrait = LeakyInstanceTrait<T> > |
| 253 struct LazyDynamicInstance { | 230 struct LazyDynamicInstance { |
| 254 typedef LazyInstanceImpl<T, DynamicallyAllocatedInstanceTrait<T>, | 231 typedef LazyInstanceImpl<T, DynamicallyAllocatedInstanceTrait<T>, |
| 255 CreateTrait, InitOnceTrait, DestroyTrait> type; | 232 CreateTrait, InitOnceTrait, DestroyTrait> type; |
| 256 }; | 233 }; |
| 257 | 234 |
| 258 } } // namespace v8::internal | 235 } } // namespace v8::internal |
| 259 | 236 |
| 260 #endif // V8_LAZY_INSTANCE_H_ | 237 #endif // V8_LAZY_INSTANCE_H_ |
| OLD | NEW |