Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(222)

Side by Side Diff: third_party/WebKit/Source/platform/heap/PersistentNode.h

Issue 2013173002: Lock CrossThreadPersistentRegion until end of weak processing. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: compile fix Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « third_party/WebKit/Source/platform/heap/Heap.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 179 matching lines...) Expand 10 before | Expand all | Expand 10 after
190 // the CrossThreadPersistent<> also clearing the persistent and freeing the PersistentNode. 190 // the CrossThreadPersistent<> also clearing the persistent and freeing the PersistentNode.
191 // 191 //
192 // 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
193 // PersistentNode reference may have been cleared out already; check for this. 193 // PersistentNode reference may have been cleared out already; check for this.
194 if (!persistentNode) 194 if (!persistentNode)
195 return; 195 return;
196 m_persistentRegion->freePersistentNode(persistentNode); 196 m_persistentRegion->freePersistentNode(persistentNode);
197 releaseStore(reinterpret_cast<void* volatile*>(&persistentNode), nullptr ); 197 releaseStore(reinterpret_cast<void* volatile*>(&persistentNode), nullptr );
198 } 198 }
199 199
200 class LockScope final {
201 STACK_ALLOCATED();
202 public:
203 LockScope(CrossThreadPersistentRegion& persistentRegion)
204 : m_persistentRegion(persistentRegion)
205 {
206 m_persistentRegion.lock();
207 }
208 ~LockScope()
209 {
210 m_persistentRegion.unlock();
211 }
212 private:
213 CrossThreadPersistentRegion& m_persistentRegion;
214 };
215
200 void tracePersistentNodes(Visitor* visitor) 216 void tracePersistentNodes(Visitor* visitor)
201 { 217 {
202 MutexLocker lock(m_mutex); 218 // If this assert triggers, you're tracing without being in a LockScope.
219 #if ENABLE(ASSERT)
220 DCHECK(m_mutex.locked());
221 #endif
203 m_persistentRegion->tracePersistentNodes(visitor, CrossThreadPersistentR egion::shouldTracePersistentNode); 222 m_persistentRegion->tracePersistentNodes(visitor, CrossThreadPersistentR egion::shouldTracePersistentNode);
204 } 223 }
205 224
206 void prepareForThreadStateTermination(ThreadState*); 225 void prepareForThreadStateTermination(ThreadState*);
207 226
208 static bool shouldTracePersistentNode(Visitor*, PersistentNode*); 227 static bool shouldTracePersistentNode(Visitor*, PersistentNode*);
209 228
210 private: 229 private:
230 friend class LockScope;
231
232 void lock()
233 {
234 m_mutex.lock();
235 }
236
237 void unlock()
238 {
239 m_mutex.unlock();
240 }
241
211 // We don't make CrossThreadPersistentRegion inherit from PersistentRegion 242 // We don't make CrossThreadPersistentRegion inherit from PersistentRegion
212 // because we don't want to virtualize performance-sensitive methods 243 // because we don't want to virtualize performance-sensitive methods
213 // such as PersistentRegion::allocate/freePersistentNode. 244 // such as PersistentRegion::allocate/freePersistentNode.
214 OwnPtr<PersistentRegion> m_persistentRegion; 245 OwnPtr<PersistentRegion> m_persistentRegion;
215 246
216 // Recursive as prepareForThreadStateTermination() clears a PersistentNode's 247 // Recursive as prepareForThreadStateTermination() clears a PersistentNode's
217 // associated Persistent<> -- it in turn freeing the PersistentNode. And bot h 248 // associated Persistent<> -- it in turn freeing the PersistentNode. And bot h
218 // CrossThreadPersistentRegion operations need a lock on the region before 249 // CrossThreadPersistentRegion operations need a lock on the region before
219 // mutating. 250 // mutating.
220 RecursiveMutex m_mutex; 251 RecursiveMutex m_mutex;
221 }; 252 };
222 253
223 } // namespace blink 254 } // namespace blink
224 255
225 #endif 256 #endif
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/platform/heap/Heap.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698