| 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" |
| (...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 170 }; | 170 }; |
| 171 | 171 |
| 172 class CrossThreadPersistentRegion final { | 172 class CrossThreadPersistentRegion final { |
| 173 USING_FAST_MALLOC(CrossThreadPersistentRegion); | 173 USING_FAST_MALLOC(CrossThreadPersistentRegion); |
| 174 public: | 174 public: |
| 175 CrossThreadPersistentRegion() : m_persistentRegion(adoptPtr(new PersistentRe
gion)) { } | 175 CrossThreadPersistentRegion() : m_persistentRegion(adoptPtr(new PersistentRe
gion)) { } |
| 176 | 176 |
| 177 void allocatePersistentNode(PersistentNode*& persistentNode, void* self, Tra
ceCallback trace) | 177 void allocatePersistentNode(PersistentNode*& persistentNode, void* self, Tra
ceCallback trace) |
| 178 { | 178 { |
| 179 MutexLocker lock(m_mutex); | 179 MutexLocker lock(m_mutex); |
| 180 persistentNode = m_persistentRegion->allocatePersistentNode(self, trace)
; | 180 PersistentNode* node = m_persistentRegion->allocatePersistentNode(self,
trace); |
| 181 releaseStore(reinterpret_cast<void* volatile*>(&persistentNode), node); |
| 181 } | 182 } |
| 182 | 183 |
| 183 void freePersistentNode(PersistentNode*& persistentNode) | 184 void freePersistentNode(PersistentNode*& persistentNode) |
| 184 { | 185 { |
| 185 MutexLocker lock(m_mutex); | 186 MutexLocker lock(m_mutex); |
| 186 // When the thread that holds the heap object that the cross-thread pers
istent shuts down, | 187 // When the thread that holds the heap object that the cross-thread pers
istent shuts down, |
| 187 // prepareForThreadStateTermination() will clear out the associated Cros
sThreadPersistent<> | 188 // prepareForThreadStateTermination() will clear out the associated Cros
sThreadPersistent<> |
| 188 // and PersistentNode so as to avoid unsafe access. This can overlap wit
h a holder of | 189 // and PersistentNode so as to avoid unsafe access. This can overlap wit
h a holder of |
| 189 // the CrossThreadPersistent<> also clearing the persistent and freeing
the PersistentNode. | 190 // the CrossThreadPersistent<> also clearing the persistent and freeing
the PersistentNode. |
| 190 // | 191 // |
| 191 // The lock ensures the updating is ordered, but by the time lock has be
en acquired the | 192 // The lock ensures the updating is ordered, but by the time lock has be
en acquired the |
| 192 // PersistentNode reference may have been cleared out already; check for
this. | 193 // PersistentNode reference may have been cleared out already; check for
this. |
| 193 if (!persistentNode) | 194 if (!persistentNode) |
| 194 return; | 195 return; |
| 195 m_persistentRegion->freePersistentNode(persistentNode); | 196 m_persistentRegion->freePersistentNode(persistentNode); |
| 196 persistentNode = nullptr; | 197 releaseStore(reinterpret_cast<void* volatile*>(&persistentNode), nullptr
); |
| 197 } | 198 } |
| 198 | 199 |
| 199 void tracePersistentNodes(Visitor* visitor) | 200 void tracePersistentNodes(Visitor* visitor) |
| 200 { | 201 { |
| 201 MutexLocker lock(m_mutex); | 202 MutexLocker lock(m_mutex); |
| 202 m_persistentRegion->tracePersistentNodes(visitor, CrossThreadPersistentR
egion::shouldTracePersistentNode); | 203 m_persistentRegion->tracePersistentNodes(visitor, CrossThreadPersistentR
egion::shouldTracePersistentNode); |
| 203 } | 204 } |
| 204 | 205 |
| 205 void prepareForThreadStateTermination(ThreadState*); | 206 void prepareForThreadStateTermination(ThreadState*); |
| 206 | 207 |
| 207 static bool shouldTracePersistentNode(Visitor*, PersistentNode*); | 208 static bool shouldTracePersistentNode(Visitor*, PersistentNode*); |
| 208 | 209 |
| 209 private: | 210 private: |
| 210 // We don't make CrossThreadPersistentRegion inherit from PersistentRegion | 211 // We don't make CrossThreadPersistentRegion inherit from PersistentRegion |
| 211 // because we don't want to virtualize performance-sensitive methods | 212 // because we don't want to virtualize performance-sensitive methods |
| 212 // such as PersistentRegion::allocate/freePersistentNode. | 213 // such as PersistentRegion::allocate/freePersistentNode. |
| 213 OwnPtr<PersistentRegion> m_persistentRegion; | 214 OwnPtr<PersistentRegion> m_persistentRegion; |
| 214 | 215 |
| 215 // Recursive as prepareForThreadStateTermination() clears a PersistentNode's | 216 // Recursive as prepareForThreadStateTermination() clears a PersistentNode's |
| 216 // associated Persistent<> -- it in turn freeing the PersistentNode. And bot
h | 217 // associated Persistent<> -- it in turn freeing the PersistentNode. And bot
h |
| 217 // CrossThreadPersistentRegion operations need a lock on the region before | 218 // CrossThreadPersistentRegion operations need a lock on the region before |
| 218 // mutating. | 219 // mutating. |
| 219 RecursiveMutex m_mutex; | 220 RecursiveMutex m_mutex; |
| 220 }; | 221 }; |
| 221 | 222 |
| 222 } // namespace blink | 223 } // namespace blink |
| 223 | 224 |
| 224 #endif | 225 #endif |
| OLD | NEW |