OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef PersistentNode_h | 5 #ifndef PersistentNode_h |
6 #define PersistentNode_h | 6 #define PersistentNode_h |
7 | 7 |
8 #include "platform/PlatformExport.h" | 8 #include "platform/PlatformExport.h" |
9 #include "platform/heap/ThreadState.h" | 9 #include "platform/heap/ThreadState.h" |
| 10 #include "wtf/Allocator.h" |
10 #include "wtf/Assertions.h" | 11 #include "wtf/Assertions.h" |
11 #include "wtf/MainThread.h" | 12 #include "wtf/MainThread.h" |
12 #include "wtf/ThreadingPrimitives.h" | 13 #include "wtf/ThreadingPrimitives.h" |
13 | 14 |
14 namespace blink { | 15 namespace blink { |
15 | 16 |
16 class CrossThreadPersistentRegion; | 17 class CrossThreadPersistentRegion; |
17 | 18 |
18 class PersistentNode final { | 19 class PersistentNode final { |
| 20 DISALLOW_NEW(); |
19 public: | 21 public: |
20 PersistentNode() | 22 PersistentNode() |
21 : m_self(nullptr) | 23 : m_self(nullptr) |
22 , m_trace(nullptr) | 24 , m_trace(nullptr) |
23 { | 25 { |
24 ASSERT(isUnused()); | 26 ASSERT(isUnused()); |
25 } | 27 } |
26 | 28 |
27 ~PersistentNode() | 29 ~PersistentNode() |
28 { | 30 { |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
89 // - m_self points to the corresponding Persistent handle. | 91 // - m_self points to the corresponding Persistent handle. |
90 // - m_trace points to the trace method. | 92 // - m_trace points to the trace method. |
91 // If this PersistentNode is freed: | 93 // If this PersistentNode is freed: |
92 // - m_self points to the next freed PersistentNode. | 94 // - m_self points to the next freed PersistentNode. |
93 // - m_trace is nullptr. | 95 // - m_trace is nullptr. |
94 void* m_self; | 96 void* m_self; |
95 TraceCallback m_trace; | 97 TraceCallback m_trace; |
96 }; | 98 }; |
97 | 99 |
98 struct PersistentNodeSlots final { | 100 struct PersistentNodeSlots final { |
| 101 USING_FAST_MALLOC(PersistentNodeSlots); |
99 private: | 102 private: |
100 static const int slotCount = 256; | 103 static const int slotCount = 256; |
101 PersistentNodeSlots* m_next; | 104 PersistentNodeSlots* m_next; |
102 PersistentNode m_slot[slotCount]; | 105 PersistentNode m_slot[slotCount]; |
103 friend class PersistentRegion; | 106 friend class PersistentRegion; |
104 friend class CrossThreadPersistentRegion; | 107 friend class CrossThreadPersistentRegion; |
105 }; | 108 }; |
106 | 109 |
107 // PersistentRegion provides a region of PersistentNodes. PersistentRegion | 110 // PersistentRegion provides a region of PersistentNodes. PersistentRegion |
108 // holds a linked list of PersistentNodeSlots, each of which stores | 111 // holds a linked list of PersistentNodeSlots, each of which stores |
109 // a predefined number of PersistentNodes. You can call allocatePersistentNode/ | 112 // a predefined number of PersistentNodes. You can call allocatePersistentNode/ |
110 // freePersistentNode to allocate/free a PersistentNode on the region. | 113 // freePersistentNode to allocate/free a PersistentNode on the region. |
111 class PLATFORM_EXPORT PersistentRegion final { | 114 class PLATFORM_EXPORT PersistentRegion final { |
| 115 USING_FAST_MALLOC(PersistentRegion); |
112 public: | 116 public: |
113 PersistentRegion() | 117 PersistentRegion() |
114 : m_freeListHead(nullptr) | 118 : m_freeListHead(nullptr) |
115 , m_slots(nullptr) | 119 , m_slots(nullptr) |
116 #if ENABLE(ASSERT) | 120 #if ENABLE(ASSERT) |
117 , m_persistentCount(0) | 121 , m_persistentCount(0) |
118 #endif | 122 #endif |
119 { | 123 { |
120 } | 124 } |
121 ~PersistentRegion(); | 125 ~PersistentRegion(); |
(...skipping 30 matching lines...) Expand all Loading... |
152 void ensurePersistentNodeSlots(void*, TraceCallback); | 156 void ensurePersistentNodeSlots(void*, TraceCallback); |
153 | 157 |
154 PersistentNode* m_freeListHead; | 158 PersistentNode* m_freeListHead; |
155 PersistentNodeSlots* m_slots; | 159 PersistentNodeSlots* m_slots; |
156 #if ENABLE(ASSERT) | 160 #if ENABLE(ASSERT) |
157 int m_persistentCount; | 161 int m_persistentCount; |
158 #endif | 162 #endif |
159 }; | 163 }; |
160 | 164 |
161 class CrossThreadPersistentRegion final { | 165 class CrossThreadPersistentRegion final { |
| 166 USING_FAST_MALLOC(CrossThreadPersistentRegion); |
162 public: | 167 public: |
163 CrossThreadPersistentRegion() : m_persistentRegion(adoptPtr(new PersistentRe
gion)) { } | 168 CrossThreadPersistentRegion() : m_persistentRegion(adoptPtr(new PersistentRe
gion)) { } |
164 | 169 |
165 PersistentNode* allocatePersistentNode(void* self, TraceCallback trace) | 170 PersistentNode* allocatePersistentNode(void* self, TraceCallback trace) |
166 { | 171 { |
167 MutexLocker lock(m_mutex); | 172 MutexLocker lock(m_mutex); |
168 return m_persistentRegion->allocatePersistentNode(self, trace); | 173 return m_persistentRegion->allocatePersistentNode(self, trace); |
169 } | 174 } |
170 | 175 |
171 void freePersistentNode(PersistentNode* persistentNode) | 176 void freePersistentNode(PersistentNode* persistentNode) |
(...skipping 14 matching lines...) Expand all Loading... |
186 // We don't make CrossThreadPersistentRegion inherit from PersistentRegion | 191 // We don't make CrossThreadPersistentRegion inherit from PersistentRegion |
187 // because we don't want to virtualize performance-sensitive methods | 192 // because we don't want to virtualize performance-sensitive methods |
188 // such as PersistentRegion::allocate/freePersistentNode. | 193 // such as PersistentRegion::allocate/freePersistentNode. |
189 OwnPtr<PersistentRegion> m_persistentRegion; | 194 OwnPtr<PersistentRegion> m_persistentRegion; |
190 Mutex m_mutex; | 195 Mutex m_mutex; |
191 }; | 196 }; |
192 | 197 |
193 } // namespace blink | 198 } // namespace blink |
194 | 199 |
195 #endif | 200 #endif |
OLD | NEW |