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

Unified Diff: third_party/WebKit/Source/platform/heap/ThreadState.h

Issue 2913303002: Avoid unsafe heap access from audio thread. (Closed)
Patch Set: Created 3 years, 7 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 side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/platform/heap/ThreadState.h
diff --git a/third_party/WebKit/Source/platform/heap/ThreadState.h b/third_party/WebKit/Source/platform/heap/ThreadState.h
index dd5f2218dfcf8884e7577a843c209b61c1b96b63..fd6b792d1213261630714c01399b97fff51b042e 100644
--- a/third_party/WebKit/Source/platform/heap/ThreadState.h
+++ b/third_party/WebKit/Source/platform/heap/ThreadState.h
@@ -320,6 +320,23 @@ class PLATFORM_EXPORT ThreadState {
ThreadState* const thread_state_;
};
+ // Per-thread lock that's held while a GC runs; can be
+ // used by non-attached threads to safely coordinate access
+ // to the heap while it is in a non-GCing state.
hongchan 2017/06/01 16:08:55 From what I understand, this should not be abused
+ class GCLockScope final {
+ STACK_ALLOCATED();
+
+ public:
+ explicit GCLockScope(ThreadState* thread_state)
+ : thread_state_(thread_state) {
+ thread_state_->active_gc_mutex_.lock();
+ }
+ ~GCLockScope() { thread_state_->active_gc_mutex_.unlock(); }
+
+ private:
+ ThreadState* const thread_state_;
+ };
+
void FlushHeapDoesNotContainCacheIfNeeded();
// Safepoint related functionality.
@@ -629,6 +646,7 @@ class PLATFORM_EXPORT ThreadState {
void ReportMemoryToV8();
friend class SafePointScope;
+ friend class GCLockScope;
static WTF::ThreadSpecific<ThreadState*>* thread_specific_;
@@ -656,6 +674,7 @@ class PLATFORM_EXPORT ThreadState {
size_t mixins_being_constructed_count_;
double accumulated_sweeping_time_;
bool object_resurrection_forbidden_;
+ Mutex active_gc_mutex_;
BaseArena* arenas_[BlinkGC::kNumberOfArenas];
int vector_backing_arena_index_;

Powered by Google App Engine
This is Rietveld 408576698