| 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 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 104 | 104 |
| 105 | 105 |
| 106 template <typename T> | 106 template <typename T> |
| 107 struct LeakyInstanceTrait { | 107 struct LeakyInstanceTrait { |
| 108 static void Destroy(T* /* instance */) {} | 108 static void Destroy(T* /* instance */) {} |
| 109 }; | 109 }; |
| 110 | 110 |
| 111 | 111 |
| 112 // Traits that define how an instance is allocated and accessed. | 112 // Traits that define how an instance is allocated and accessed. |
| 113 | 113 |
| 114 // TODO(kalmard): __alignof__ is only defined for GCC > 4.2. Fix alignment issue | |
| 115 // on MIPS with other compilers. | |
| 116 #if defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ > 2)) | |
| 117 #define LAZY_ALIGN(x) __attribute__((aligned(__alignof__(x)))) | |
| 118 #else | |
| 119 #define LAZY_ALIGN(x) | |
| 120 #endif | |
| 121 | |
| 122 template <typename T> | 114 template <typename T> |
| 123 struct StaticallyAllocatedInstanceTrait { | 115 struct StaticallyAllocatedInstanceTrait { |
| 124 typedef char StorageType[sizeof(T)] LAZY_ALIGN(T); | 116 typedef char StorageType[sizeof(T)] V8_ALIGNAS(V8_ALIGNOF(T)); |
| 125 | 117 |
| 126 static T* MutableInstance(StorageType* storage) { | 118 static T* MutableInstance(StorageType* storage) { |
| 127 return reinterpret_cast<T*>(storage); | 119 return reinterpret_cast<T*>(storage); |
| 128 } | 120 } |
| 129 | 121 |
| 130 template <typename ConstructTrait> | 122 template <typename ConstructTrait> |
| 131 static void InitStorageUsingTrait(StorageType* storage) { | 123 static void InitStorageUsingTrait(StorageType* storage) { |
| 132 ConstructTrait::Construct(MutableInstance(storage)); | 124 ConstructTrait::Construct(MutableInstance(storage)); |
| 133 } | 125 } |
| 134 }; | 126 }; |
| 135 | 127 |
| 136 #undef LAZY_ALIGN | |
| 137 | |
| 138 | 128 |
| 139 template <typename T> | 129 template <typename T> |
| 140 struct DynamicallyAllocatedInstanceTrait { | 130 struct DynamicallyAllocatedInstanceTrait { |
| 141 typedef T* StorageType; | 131 typedef T* StorageType; |
| 142 | 132 |
| 143 static T* MutableInstance(StorageType* storage) { | 133 static T* MutableInstance(StorageType* storage) { |
| 144 return *storage; | 134 return *storage; |
| 145 } | 135 } |
| 146 | 136 |
| 147 template <typename CreateTrait> | 137 template <typename CreateTrait> |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 254 typename InitOnceTrait = SingleThreadInitOnceTrait, | 244 typename InitOnceTrait = SingleThreadInitOnceTrait, |
| 255 typename DestroyTrait = LeakyInstanceTrait<T> > | 245 typename DestroyTrait = LeakyInstanceTrait<T> > |
| 256 struct LazyDynamicInstance { | 246 struct LazyDynamicInstance { |
| 257 typedef LazyInstanceImpl<T, DynamicallyAllocatedInstanceTrait<T>, | 247 typedef LazyInstanceImpl<T, DynamicallyAllocatedInstanceTrait<T>, |
| 258 CreateTrait, InitOnceTrait, DestroyTrait> type; | 248 CreateTrait, InitOnceTrait, DestroyTrait> type; |
| 259 }; | 249 }; |
| 260 | 250 |
| 261 } } // namespace v8::internal | 251 } } // namespace v8::internal |
| 262 | 252 |
| 263 #endif // V8_LAZY_INSTANCE_H_ | 253 #endif // V8_LAZY_INSTANCE_H_ |
| OLD | NEW |