OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2008 Apple Inc. All Rights Reserved. | 2 * Copyright (C) 2008 Apple Inc. All Rights Reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
6 * are met: | 6 * are met: |
7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
(...skipping 11 matching lines...) Expand all Loading... |
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
24 */ | 24 */ |
25 | 25 |
26 #ifndef WTF_StdLibExtras_h | 26 #ifndef WTF_StdLibExtras_h |
27 #define WTF_StdLibExtras_h | 27 #define WTF_StdLibExtras_h |
28 | 28 |
29 #include "wtf/Assertions.h" | 29 #include "wtf/Assertions.h" |
30 #include "wtf/CPU.h" | 30 #include "wtf/CPU.h" |
31 #include "wtf/CheckedArithmetic.h" | 31 #include "wtf/CheckedArithmetic.h" |
32 #include "wtf/LeakAnnotations.h" | |
33 #include <cstddef> | 32 #include <cstddef> |
34 | 33 |
35 #if ENABLE(ASSERT) | 34 #if ENABLE(ASSERT) |
36 #include "wtf/Noncopyable.h" | 35 #include "wtf/Noncopyable.h" |
37 #include "wtf/Threading.h" | 36 #include "wtf/Threading.h" |
38 | 37 |
39 class WTF_EXPORT StaticLocalVerifier { | 38 class WTF_EXPORT StaticLocalVerifier { |
40 WTF_MAKE_NONCOPYABLE(StaticLocalVerifier); | 39 WTF_MAKE_NONCOPYABLE(StaticLocalVerifier); |
41 public: | 40 public: |
42 StaticLocalVerifier() | 41 StaticLocalVerifier() |
43 : m_safelyInitialized(WTF::isBeforeThreadCreated()) | 42 : m_safelyInitialized(WTF::isBeforeThreadCreated()) |
44 , m_thread(WTF::currentThread()) | 43 , m_thread(WTF::currentThread()) |
45 { | 44 { |
46 } | 45 } |
47 | 46 |
48 bool isNotRacy() | 47 bool isNotRacy() |
49 { | 48 { |
50 // Make sure that this 1) is safely initialized, 2) keeps being called | 49 // Make sure that this 1) is safely initialized, 2) keeps being called |
51 // on the same thread, or 3) is called within | 50 // on the same thread, or 3) is called within |
52 // AtomicallyInitializedStatic (i.e. with a lock held). | 51 // AtomicallyInitializedStatic (i.e. with a lock held). |
53 return m_safelyInitialized || m_thread == WTF::currentThread() || WTF::i
sAtomicallyInitializedStaticMutexLockHeld(); | 52 return m_safelyInitialized || m_thread == WTF::currentThread() || WTF::i
sAtomicallyInitializedStaticMutexLockHeld(); |
54 } | 53 } |
55 | 54 |
56 private: | 55 private: |
57 bool m_safelyInitialized; | 56 bool m_safelyInitialized; |
58 ThreadIdentifier m_thread; | 57 ThreadIdentifier m_thread; |
59 }; | 58 }; |
60 #endif | 59 #endif |
61 | 60 |
62 // Use DEFINE_STATIC_LOCAL() to declare and define a static local variable (stat
ic T;) | 61 // Use this to declare and define a static local variable (static T;) so that |
63 // so that it is leaked and its destructors are not called at exit. | 62 // it is leaked so that its destructors are not called at exit. |
64 // | 63 #ifndef DEFINE_STATIC_LOCAL |
65 // To cooperate with leak detection, the objects held onto by these local static
s | 64 |
66 // will in some cases have to be finalized prior to leak checking. This only app
lies | |
67 // to static references to Oilpan heap objects and what they transitively hold o
n to. | |
68 // LEAK_SANITIZER_REGISTER_STATIC_LOCAL() takes care of the details. | |
69 // | |
70 #if ENABLE(ASSERT) | 65 #if ENABLE(ASSERT) |
71 #define DEFINE_STATIC_LOCAL(type, name, arguments) \ | 66 #define DEFINE_STATIC_LOCAL(type, name, arguments) \ |
72 static StaticLocalVerifier name##StaticLocalVerifier; \ | 67 static StaticLocalVerifier name##StaticLocalVerifier; \ |
73 ASSERT(name##StaticLocalVerifier.isNotRacy()); \ | 68 ASSERT(name##StaticLocalVerifier.isNotRacy()); \ |
74 static type& name = *LEAK_SANITIZER_REGISTER_STATIC_LOCAL(type, new type arg
uments) | 69 static type& name = *new type arguments |
75 #else | 70 #else |
76 #define DEFINE_STATIC_LOCAL(type, name, arguments) \ | 71 #define DEFINE_STATIC_LOCAL(type, name, arguments) \ |
77 static type& name = *LEAK_SANITIZER_REGISTER_STATIC_LOCAL(type, new type arg
uments) | 72 static type& name = *new type arguments |
78 #endif | 73 #endif |
79 | 74 |
| 75 #endif |
| 76 |
| 77 |
80 // Use this to declare and define a static local pointer to a ref-counted object
so that | 78 // Use this to declare and define a static local pointer to a ref-counted object
so that |
81 // it is leaked so that the object's destructors are not called at exit. | 79 // it is leaked so that the object's destructors are not called at exit. |
82 // This macro should be used with ref-counted objects rather than DEFINE_STATIC_
LOCAL macro, | 80 // This macro should be used with ref-counted objects rather than DEFINE_STATIC_
LOCAL macro, |
83 // as this macro does not lead to an extra memory allocation. | 81 // as this macro does not lead to an extra memory allocation. |
| 82 #ifndef DEFINE_STATIC_REF |
84 #define DEFINE_STATIC_REF(type, name, arguments) \ | 83 #define DEFINE_STATIC_REF(type, name, arguments) \ |
85 static type* name = PassRefPtr<type>(arguments).leakRef(); | 84 static type* name = PassRefPtr<type>(arguments).leakRef(); |
| 85 #endif |
86 | 86 |
87 /* | 87 /* |
88 * The reinterpret_cast<Type1*>([pointer to Type2]) expressions - where | 88 * The reinterpret_cast<Type1*>([pointer to Type2]) expressions - where |
89 * sizeof(Type1) > sizeof(Type2) - cause the following warning on ARM with GCC: | 89 * sizeof(Type1) > sizeof(Type2) - cause the following warning on ARM with GCC: |
90 * increases required alignment of target type. | 90 * increases required alignment of target type. |
91 * | 91 * |
92 * An implicit or an extra static_cast<void*> bypasses the warning. | 92 * An implicit or an extra static_cast<void*> bypasses the warning. |
93 * For more info see the following bugzilla entries: | 93 * For more info see the following bugzilla entries: |
94 * - https://bugs.webkit.org/show_bug.cgi?id=38045 | 94 * - https://bugs.webkit.org/show_bug.cgi?id=38045 |
95 * - http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43976 | 95 * - http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43976 |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
162 inline void* operator new(size_t, NotNullTag, void* location) | 162 inline void* operator new(size_t, NotNullTag, void* location) |
163 { | 163 { |
164 ASSERT(location); | 164 ASSERT(location); |
165 return location; | 165 return location; |
166 } | 166 } |
167 | 167 |
168 using WTF::bitwise_cast; | 168 using WTF::bitwise_cast; |
169 using WTF::safeCast; | 169 using WTF::safeCast; |
170 | 170 |
171 #endif // WTF_StdLibExtras_h | 171 #endif // WTF_StdLibExtras_h |
OLD | NEW |