| 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" |
| 32 #include <cstddef> | 33 #include <cstddef> |
| 33 | 34 |
| 34 #if ENABLE(ASSERT) | 35 #if ENABLE(ASSERT) |
| 35 #include "wtf/Noncopyable.h" | 36 #include "wtf/Noncopyable.h" |
| 36 #include "wtf/Threading.h" | 37 #include "wtf/Threading.h" |
| 37 | 38 |
| 38 class WTF_EXPORT StaticLocalVerifier { | 39 class WTF_EXPORT StaticLocalVerifier { |
| 39 WTF_MAKE_NONCOPYABLE(StaticLocalVerifier); | 40 WTF_MAKE_NONCOPYABLE(StaticLocalVerifier); |
| 40 public: | 41 public: |
| 41 StaticLocalVerifier() | 42 StaticLocalVerifier() |
| 42 : m_safelyInitialized(WTF::isBeforeThreadCreated()) | 43 : m_safelyInitialized(WTF::isBeforeThreadCreated()) |
| 43 , m_thread(WTF::currentThread()) | 44 , m_thread(WTF::currentThread()) |
| 44 { | 45 { |
| 45 } | 46 } |
| 46 | 47 |
| 47 bool isNotRacy() | 48 bool isNotRacy() |
| 48 { | 49 { |
| 49 // Make sure that this 1) is safely initialized, 2) keeps being called | 50 // Make sure that this 1) is safely initialized, 2) keeps being called |
| 50 // on the same thread, or 3) is called within | 51 // on the same thread, or 3) is called within |
| 51 // AtomicallyInitializedStatic (i.e. with a lock held). | 52 // AtomicallyInitializedStatic (i.e. with a lock held). |
| 52 return m_safelyInitialized || m_thread == WTF::currentThread() || WTF::i
sAtomicallyInitializedStaticMutexLockHeld(); | 53 return m_safelyInitialized || m_thread == WTF::currentThread() || WTF::i
sAtomicallyInitializedStaticMutexLockHeld(); |
| 53 } | 54 } |
| 54 | 55 |
| 55 private: | 56 private: |
| 56 bool m_safelyInitialized; | 57 bool m_safelyInitialized; |
| 57 ThreadIdentifier m_thread; | 58 ThreadIdentifier m_thread; |
| 58 }; | 59 }; |
| 59 #endif | 60 #endif |
| 60 | 61 |
| 61 // Use this to declare and define a static local variable (static T;) so that | 62 // Use DEFINE_STATIC_LOCAL() to declare and define a static local variable (stat
ic T;) |
| 62 // it is leaked so that its destructors are not called at exit. | 63 // so that it is leaked and its destructors are not called at exit. |
| 63 #ifndef DEFINE_STATIC_LOCAL | 64 // |
| 64 | 65 // To cooperate with leak detection, the objects held onto by these local static
s |
| 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 // |
| 65 #if ENABLE(ASSERT) | 70 #if ENABLE(ASSERT) |
| 66 #define DEFINE_STATIC_LOCAL(type, name, arguments) \ | 71 #define DEFINE_STATIC_LOCAL(type, name, arguments) \ |
| 67 static StaticLocalVerifier name##StaticLocalVerifier; \ | 72 static StaticLocalVerifier name##StaticLocalVerifier; \ |
| 68 ASSERT(name##StaticLocalVerifier.isNotRacy()); \ | 73 ASSERT(name##StaticLocalVerifier.isNotRacy()); \ |
| 69 static type& name = *new type arguments | 74 static type& name = *LEAK_SANITIZER_REGISTER_STATIC_LOCAL(type, new type arg
uments) |
| 70 #else | 75 #else |
| 71 #define DEFINE_STATIC_LOCAL(type, name, arguments) \ | 76 #define DEFINE_STATIC_LOCAL(type, name, arguments) \ |
| 72 static type& name = *new type arguments | 77 static type& name = *LEAK_SANITIZER_REGISTER_STATIC_LOCAL(type, new type arg
uments) |
| 73 #endif | 78 #endif |
| 74 | 79 |
| 75 #endif | |
| 76 | |
| 77 | |
| 78 // Use this to declare and define a static local pointer to a ref-counted object
so that | 80 // Use this to declare and define a static local pointer to a ref-counted object
so that |
| 79 // it is leaked so that the object's destructors are not called at exit. | 81 // it is leaked so that the object's destructors are not called at exit. |
| 80 // This macro should be used with ref-counted objects rather than DEFINE_STATIC_
LOCAL macro, | 82 // This macro should be used with ref-counted objects rather than DEFINE_STATIC_
LOCAL macro, |
| 81 // as this macro does not lead to an extra memory allocation. | 83 // as this macro does not lead to an extra memory allocation. |
| 82 #ifndef DEFINE_STATIC_REF | |
| 83 #define DEFINE_STATIC_REF(type, name, arguments) \ | 84 #define DEFINE_STATIC_REF(type, name, arguments) \ |
| 84 static type* name = PassRefPtr<type>(arguments).leakRef(); | 85 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 |