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

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

Issue 2065343002: Lock CrossThreadPersistentRegion until end of weak processing. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@2704
Patch Set: 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 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
173 MutexLocker lock(m_mutex); 173 MutexLocker lock(m_mutex);
174 return m_persistentRegion->allocatePersistentNode(self, trace); 174 return m_persistentRegion->allocatePersistentNode(self, trace);
175 } 175 }
176 176
177 void freePersistentNode(PersistentNode* persistentNode) 177 void freePersistentNode(PersistentNode* persistentNode)
178 { 178 {
179 MutexLocker lock(m_mutex); 179 MutexLocker lock(m_mutex);
180 m_persistentRegion->freePersistentNode(persistentNode); 180 m_persistentRegion->freePersistentNode(persistentNode);
181 } 181 }
182 182
183 class LockScope final {
184 STACK_ALLOCATED();
185 public:
186 LockScope(CrossThreadPersistentRegion& persistentRegion)
187 : m_persistentRegion(persistentRegion)
188 {
189 m_persistentRegion.lock();
190 }
191 ~LockScope()
192 {
193 m_persistentRegion.unlock();
194 }
195 private:
196 CrossThreadPersistentRegion& m_persistentRegion;
197 };
198
183 void tracePersistentNodes(Visitor* visitor) 199 void tracePersistentNodes(Visitor* visitor)
184 { 200 {
185 MutexLocker lock(m_mutex); 201 // If this assert triggers, you're tracing without being in a LockScope.
202 ASSERT(m_mutex.locked());
186 m_persistentRegion->tracePersistentNodes(visitor); 203 m_persistentRegion->tracePersistentNodes(visitor);
187 } 204 }
188 205
189 void prepareForThreadStateTermination(ThreadState*); 206 void prepareForThreadStateTermination(ThreadState*);
190 207
191 private: 208 private:
209 friend class LockScope;
210
211 void lock()
212 {
213 m_mutex.lock();
214 }
215
216 void unlock()
217 {
218 m_mutex.unlock();
219 }
220
192 // We don't make CrossThreadPersistentRegion inherit from PersistentRegion 221 // We don't make CrossThreadPersistentRegion inherit from PersistentRegion
193 // because we don't want to virtualize performance-sensitive methods 222 // because we don't want to virtualize performance-sensitive methods
194 // such as PersistentRegion::allocate/freePersistentNode. 223 // such as PersistentRegion::allocate/freePersistentNode.
195 OwnPtr<PersistentRegion> m_persistentRegion; 224 OwnPtr<PersistentRegion> m_persistentRegion;
196 Mutex m_mutex; 225 Mutex m_mutex;
197 }; 226 };
198 227
199 } // namespace blink 228 } // namespace blink
200 229
201 #endif 230 #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