| 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/Allocator.h" |
| 11 #include "wtf/Assertions.h" | 11 #include "wtf/Assertions.h" |
| 12 #include "wtf/PtrUtil.h" |
| 12 #include "wtf/ThreadingPrimitives.h" | 13 #include "wtf/ThreadingPrimitives.h" |
| 14 #include <memory> |
| 13 | 15 |
| 14 namespace blink { | 16 namespace blink { |
| 15 | 17 |
| 16 class CrossThreadPersistentRegion; | 18 class CrossThreadPersistentRegion; |
| 17 | 19 |
| 18 class PersistentNode final { | 20 class PersistentNode final { |
| 19 DISALLOW_NEW(); | 21 DISALLOW_NEW(); |
| 20 public: | 22 public: |
| 21 PersistentNode() | 23 PersistentNode() |
| 22 : m_self(nullptr) | 24 : m_self(nullptr) |
| (...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 165 PersistentNode* m_freeListHead; | 167 PersistentNode* m_freeListHead; |
| 166 PersistentNodeSlots* m_slots; | 168 PersistentNodeSlots* m_slots; |
| 167 #if ENABLE(ASSERT) | 169 #if ENABLE(ASSERT) |
| 168 int m_persistentCount; | 170 int m_persistentCount; |
| 169 #endif | 171 #endif |
| 170 }; | 172 }; |
| 171 | 173 |
| 172 class CrossThreadPersistentRegion final { | 174 class CrossThreadPersistentRegion final { |
| 173 USING_FAST_MALLOC(CrossThreadPersistentRegion); | 175 USING_FAST_MALLOC(CrossThreadPersistentRegion); |
| 174 public: | 176 public: |
| 175 CrossThreadPersistentRegion() : m_persistentRegion(adoptPtr(new PersistentRe
gion)) { } | 177 CrossThreadPersistentRegion() : m_persistentRegion(wrapUnique(new Persistent
Region)) { } |
| 176 | 178 |
| 177 void allocatePersistentNode(PersistentNode*& persistentNode, void* self, Tra
ceCallback trace) | 179 void allocatePersistentNode(PersistentNode*& persistentNode, void* self, Tra
ceCallback trace) |
| 178 { | 180 { |
| 179 MutexLocker lock(m_mutex); | 181 MutexLocker lock(m_mutex); |
| 180 PersistentNode* node = m_persistentRegion->allocatePersistentNode(self,
trace); | 182 PersistentNode* node = m_persistentRegion->allocatePersistentNode(self,
trace); |
| 181 releaseStore(reinterpret_cast<void* volatile*>(&persistentNode), node); | 183 releaseStore(reinterpret_cast<void* volatile*>(&persistentNode), node); |
| 182 } | 184 } |
| 183 | 185 |
| 184 void freePersistentNode(PersistentNode*& persistentNode) | 186 void freePersistentNode(PersistentNode*& persistentNode) |
| 185 { | 187 { |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 235 } | 237 } |
| 236 | 238 |
| 237 void unlock() | 239 void unlock() |
| 238 { | 240 { |
| 239 m_mutex.unlock(); | 241 m_mutex.unlock(); |
| 240 } | 242 } |
| 241 | 243 |
| 242 // We don't make CrossThreadPersistentRegion inherit from PersistentRegion | 244 // We don't make CrossThreadPersistentRegion inherit from PersistentRegion |
| 243 // because we don't want to virtualize performance-sensitive methods | 245 // because we don't want to virtualize performance-sensitive methods |
| 244 // such as PersistentRegion::allocate/freePersistentNode. | 246 // such as PersistentRegion::allocate/freePersistentNode. |
| 245 OwnPtr<PersistentRegion> m_persistentRegion; | 247 std::unique_ptr<PersistentRegion> m_persistentRegion; |
| 246 | 248 |
| 247 // Recursive as prepareForThreadStateTermination() clears a PersistentNode's | 249 // Recursive as prepareForThreadStateTermination() clears a PersistentNode's |
| 248 // associated Persistent<> -- it in turn freeing the PersistentNode. And bot
h | 250 // associated Persistent<> -- it in turn freeing the PersistentNode. And bot
h |
| 249 // CrossThreadPersistentRegion operations need a lock on the region before | 251 // CrossThreadPersistentRegion operations need a lock on the region before |
| 250 // mutating. | 252 // mutating. |
| 251 RecursiveMutex m_mutex; | 253 RecursiveMutex m_mutex; |
| 252 }; | 254 }; |
| 253 | 255 |
| 254 } // namespace blink | 256 } // namespace blink |
| 255 | 257 |
| 256 #endif | 258 #endif |
| OLD | NEW |