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 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
52 // AtomicallyInitializedStatic (i.e. with a lock held). | 52 // AtomicallyInitializedStatic (i.e. with a lock held). |
53 return m_safelyInitialized || m_thread == WTF::currentThread() || WTF::i
sAtomicallyInitializedStaticMutexLockHeld(); | 53 return m_safelyInitialized || m_thread == WTF::currentThread() || WTF::i
sAtomicallyInitializedStaticMutexLockHeld(); |
54 } | 54 } |
55 | 55 |
56 private: | 56 private: |
57 bool m_safelyInitialized; | 57 bool m_safelyInitialized; |
58 ThreadIdentifier m_thread; | 58 ThreadIdentifier m_thread; |
59 }; | 59 }; |
60 #endif | 60 #endif |
61 | 61 |
| 62 // A direct static local to a Blink garbage collected objects isn't allowed; |
| 63 // must be wrapped up with a persistent reference. |
| 64 #define STATIC_ASSERT_FOR_LOCAL_WITH_GARBAGE_COLLECTED_TYPE(Name, Type) \ |
| 65 using Name##NoConstType = std::remove_const<Type>::type; \ |
| 66 using Name##NoPointerType = std::remove_pointer<Name##NoConstType>::type; \ |
| 67 using Name##NoReferenceType = std::remove_reference<Name##NoPointerType>::ty
pe; \ |
| 68 static_assert(!WTF::IsGarbageCollectedType<Name##NoReferenceType>::value ||
WTF::IsPersistentReferenceType<Name##NoReferenceType>::value, "Garbage collected
static local needs to be wrapped up with a persistent reference") |
| 69 |
62 // Use DEFINE_STATIC_LOCAL() to declare and define a static local variable (stat
ic T;) | 70 // Use DEFINE_STATIC_LOCAL() to declare and define a static local variable (stat
ic T;) |
63 // so that it is leaked and its destructors are not called at exit. | 71 // so that it is leaked and its destructors are not called at exit. |
64 // | 72 // |
65 // To cooperate with leak detection, the objects held onto by these local static
s | 73 // 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 | 74 // 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. | 75 // 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. | 76 // LEAK_SANITIZER_REGISTER_STATIC_LOCAL() takes care of the details. |
69 // | 77 // |
70 #if ENABLE(ASSERT) | 78 #if ENABLE(ASSERT) |
71 #define DEFINE_STATIC_LOCAL(type, name, arguments) \ | 79 #define DEFINE_STATIC_LOCAL(Type, Name, Arguments) \ |
72 static StaticLocalVerifier name##StaticLocalVerifier; \ | 80 STATIC_ASSERT_FOR_LOCAL_WITH_GARBAGE_COLLECTED_TYPE(Name, Type); \ |
73 ASSERT(name##StaticLocalVerifier.isNotRacy()); \ | 81 static StaticLocalVerifier Name##StaticLocalVerifier; \ |
74 static type& name = *LEAK_SANITIZER_REGISTER_STATIC_LOCAL(type, new type arg
uments) | 82 ASSERT(Name##StaticLocalVerifier.isNotRacy()); \ |
| 83 static Type& Name = *LEAK_SANITIZER_REGISTER_STATIC_LOCAL(Type, new Type Arg
uments) |
75 #else | 84 #else |
76 #define DEFINE_STATIC_LOCAL(type, name, arguments) \ | 85 #define DEFINE_STATIC_LOCAL(Type, Name, Arguments) \ |
77 static type& name = *LEAK_SANITIZER_REGISTER_STATIC_LOCAL(type, new type arg
uments) | 86 STATIC_ASSERT_FOR_LOCAL_WITH_GARBAGE_COLLECTED_TYPE(Name, Type); \ |
| 87 static Type& Name = *LEAK_SANITIZER_REGISTER_STATIC_LOCAL(Type, new Type Arg
uments) |
78 #endif | 88 #endif |
79 | 89 |
80 // Use this to declare and define a static local pointer to a ref-counted object
so that | 90 // 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. | 91 // 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, | 92 // 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. | 93 // as this macro does not lead to an extra memory allocation. |
84 #define DEFINE_STATIC_REF(type, name, arguments) \ | 94 #define DEFINE_STATIC_REF(type, name, arguments) \ |
85 static type* name = PassRefPtr<type>(arguments).leakRef(); | 95 static type* name = PassRefPtr<type>(arguments).leakRef(); |
86 | 96 |
87 /* | 97 /* |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
162 inline void* operator new(size_t, NotNullTag, void* location) | 172 inline void* operator new(size_t, NotNullTag, void* location) |
163 { | 173 { |
164 ASSERT(location); | 174 ASSERT(location); |
165 return location; | 175 return location; |
166 } | 176 } |
167 | 177 |
168 using WTF::bitwise_cast; | 178 using WTF::bitwise_cast; |
169 using WTF::safeCast; | 179 using WTF::safeCast; |
170 | 180 |
171 #endif // WTF_StdLibExtras_h | 181 #endif // WTF_StdLibExtras_h |
OLD | NEW |