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 | 114 // TODO(kalmard): __alignof__ is only defined for GCC >= 4.3. |
115 // on MIPS with other compilers. | 115 // Fix alignment issue on MIPS with other compilers. |
116 #if defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ > 2)) | 116 #if V8_GNUC_PREREQ(4, 3) |
117 #define LAZY_ALIGN(x) __attribute__((aligned(__alignof__(x)))) | 117 #define LAZY_ALIGN(x) __attribute__((aligned(__alignof__(x)))) |
118 #else | 118 #else |
119 #define LAZY_ALIGN(x) | 119 #define LAZY_ALIGN(x) |
120 #endif | 120 #endif |
121 | 121 |
122 template <typename T> | 122 template <typename T> |
123 struct StaticallyAllocatedInstanceTrait { | 123 struct StaticallyAllocatedInstanceTrait { |
124 typedef char StorageType[sizeof(T)] LAZY_ALIGN(T); | 124 typedef char StorageType[sizeof(T)] LAZY_ALIGN(T); |
125 | 125 |
126 static T* MutableInstance(StorageType* storage) { | 126 static T* MutableInstance(StorageType* storage) { |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
254 typename InitOnceTrait = SingleThreadInitOnceTrait, | 254 typename InitOnceTrait = SingleThreadInitOnceTrait, |
255 typename DestroyTrait = LeakyInstanceTrait<T> > | 255 typename DestroyTrait = LeakyInstanceTrait<T> > |
256 struct LazyDynamicInstance { | 256 struct LazyDynamicInstance { |
257 typedef LazyInstanceImpl<T, DynamicallyAllocatedInstanceTrait<T>, | 257 typedef LazyInstanceImpl<T, DynamicallyAllocatedInstanceTrait<T>, |
258 CreateTrait, InitOnceTrait, DestroyTrait> type; | 258 CreateTrait, InitOnceTrait, DestroyTrait> type; |
259 }; | 259 }; |
260 | 260 |
261 } } // namespace v8::internal | 261 } } // namespace v8::internal |
262 | 262 |
263 #endif // V8_LAZY_INSTANCE_H_ | 263 #endif // V8_LAZY_INSTANCE_H_ |
OLD | NEW |