| 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 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 173 void* self, | 173 void* self, |
| 174 TraceCallback trace) { | 174 TraceCallback trace) { |
| 175 MutexLocker lock(m_mutex); | 175 MutexLocker lock(m_mutex); |
| 176 PersistentNode* node = | 176 PersistentNode* node = |
| 177 m_persistentRegion->allocatePersistentNode(self, trace); | 177 m_persistentRegion->allocatePersistentNode(self, trace); |
| 178 releaseStore(reinterpret_cast<void* volatile*>(&persistentNode), node); | 178 releaseStore(reinterpret_cast<void* volatile*>(&persistentNode), node); |
| 179 } | 179 } |
| 180 | 180 |
| 181 void freePersistentNode(PersistentNode*& persistentNode) { | 181 void freePersistentNode(PersistentNode*& persistentNode) { |
| 182 MutexLocker lock(m_mutex); | 182 MutexLocker lock(m_mutex); |
| 183 // When the thread that holds the heap object that the cross-thread persiste
nt shuts down, | 183 // When the thread that holds the heap object that the cross-thread |
| 184 // prepareForThreadStateTermination() will clear out the associated CrossThr
eadPersistent<> | 184 // persistent shuts down, prepareForThreadStateTermination() will clear out |
| 185 // and PersistentNode so as to avoid unsafe access. This can overlap with a
holder of | 185 // the associated CrossThreadPersistent<> and PersistentNode so as to avoid |
| 186 // the CrossThreadPersistent<> also clearing the persistent and freeing the
PersistentNode. | 186 // unsafe access. This can overlap with a holder of the |
| 187 // CrossThreadPersistent<> also clearing the persistent and freeing the |
| 188 // PersistentNode. |
| 187 // | 189 // |
| 188 // The lock ensures the updating is ordered, but by the time lock has been a
cquired the | 190 // The lock ensures the updating is ordered, but by the time lock has been |
| 189 // PersistentNode reference may have been cleared out already; check for thi
s. | 191 // acquired the PersistentNode reference may have been cleared out already; |
| 192 // check for this. |
| 190 if (!persistentNode) | 193 if (!persistentNode) |
| 191 return; | 194 return; |
| 192 m_persistentRegion->freePersistentNode(persistentNode); | 195 m_persistentRegion->freePersistentNode(persistentNode); |
| 193 releaseStore(reinterpret_cast<void* volatile*>(&persistentNode), nullptr); | 196 releaseStore(reinterpret_cast<void* volatile*>(&persistentNode), nullptr); |
| 194 } | 197 } |
| 195 | 198 |
| 196 class LockScope final { | 199 class LockScope final { |
| 197 STACK_ALLOCATED(); | 200 STACK_ALLOCATED(); |
| 198 | 201 |
| 199 public: | 202 public: |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 236 // Recursive as prepareForThreadStateTermination() clears a PersistentNode's | 239 // Recursive as prepareForThreadStateTermination() clears a PersistentNode's |
| 237 // associated Persistent<> -- it in turn freeing the PersistentNode. And both | 240 // associated Persistent<> -- it in turn freeing the PersistentNode. And both |
| 238 // CrossThreadPersistentRegion operations need a lock on the region before | 241 // CrossThreadPersistentRegion operations need a lock on the region before |
| 239 // mutating. | 242 // mutating. |
| 240 RecursiveMutex m_mutex; | 243 RecursiveMutex m_mutex; |
| 241 }; | 244 }; |
| 242 | 245 |
| 243 } // namespace blink | 246 } // namespace blink |
| 244 | 247 |
| 245 #endif | 248 #endif |
| OLD | NEW |