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 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
58 // providing your own trait: | 58 // providing your own trait: |
59 // Example usage: | 59 // Example usage: |
60 // struct MyCreateTrait { | 60 // struct MyCreateTrait { |
61 // static void Construct(MyClass* allocated_ptr) { | 61 // static void Construct(MyClass* allocated_ptr) { |
62 // new (allocated_ptr) MyClass(/* extra parameters... */); | 62 // new (allocated_ptr) MyClass(/* extra parameters... */); |
63 // } | 63 // } |
64 // }; | 64 // }; |
65 // static LazyInstance<MyClass, MyCreateTrait>::type my_instance = | 65 // static LazyInstance<MyClass, MyCreateTrait>::type my_instance = |
66 // LAZY_INSTANCE_INITIALIZER; | 66 // LAZY_INSTANCE_INITIALIZER; |
67 // | 67 // |
68 // WARNING: This implementation of LazyInstance is NOT thread-safe by default. | 68 // WARNINGS: |
69 // See ThreadSafeInitOnceTrait declared below for that. | 69 // - This implementation of LazyInstance is NOT THREAD-SAFE by default. See |
| 70 // ThreadSafeInitOnceTrait declared below for that. |
| 71 // - Lazy initialization comes with a cost. Make sure that you don't use it on |
| 72 // critical path. Consider adding your initialization code to a function |
| 73 // which is explicitly called once. |
70 // | 74 // |
71 // Notes for advanced users: | 75 // Notes for advanced users: |
72 // LazyInstance can actually be used in two different ways: | 76 // LazyInstance can actually be used in two different ways: |
73 // | 77 // |
74 // - "Static mode" which is the default mode since it is the most efficient | 78 // - "Static mode" which is the default mode since it is the most efficient |
75 // (no extra heap allocation). In this mode, the instance is statically | 79 // (no extra heap allocation). In this mode, the instance is statically |
76 // allocated (stored in the global data section at compile time). | 80 // allocated (stored in the global data section at compile time). |
77 // The macro LAZY_STATIC_INSTANCE_INITIALIZER (= LAZY_INSTANCE_INITIALIZER) | 81 // The macro LAZY_STATIC_INSTANCE_INITIALIZER (= LAZY_INSTANCE_INITIALIZER) |
78 // must be used to initialize static lazy instances. | 82 // must be used to initialize static lazy instances. |
79 // | 83 // |
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
239 typename InitOnceTrait = SingleThreadInitOnceTrait, | 243 typename InitOnceTrait = SingleThreadInitOnceTrait, |
240 typename DestroyTrait = LeakyInstanceTrait<T> > | 244 typename DestroyTrait = LeakyInstanceTrait<T> > |
241 struct LazyDynamicInstance { | 245 struct LazyDynamicInstance { |
242 typedef LazyInstanceImpl<T, DynamicallyAllocatedInstanceTrait<T>, | 246 typedef LazyInstanceImpl<T, DynamicallyAllocatedInstanceTrait<T>, |
243 CreateTrait, InitOnceTrait, DestroyTrait> type; | 247 CreateTrait, InitOnceTrait, DestroyTrait> type; |
244 }; | 248 }; |
245 | 249 |
246 } } // namespace v8::internal | 250 } } // namespace v8::internal |
247 | 251 |
248 #endif // V8_LAZY_INSTANCE_H_ | 252 #endif // V8_LAZY_INSTANCE_H_ |
OLD | NEW |