Index: third_party/WebKit/Source/core/workers/WorkerBackingThread.cpp |
diff --git a/third_party/WebKit/Source/core/workers/WorkerBackingThread.cpp b/third_party/WebKit/Source/core/workers/WorkerBackingThread.cpp |
index 040ce92ea79208362ca3f48cfceb67291d092614..7267083c7053962b89296c7c05e654b6b6691cce 100644 |
--- a/third_party/WebKit/Source/core/workers/WorkerBackingThread.cpp |
+++ b/third_party/WebKit/Source/core/workers/WorkerBackingThread.cpp |
@@ -17,6 +17,34 @@ |
namespace blink { |
+#define DEFINE_STATIC_LOCAL_WITH_LOCK(type, name, arguments) \ |
+ ASSERT(isolatesMutex().locked()); \ |
+ static type& name = *new type arguments |
+ |
+static Mutex& isolatesMutex() |
+{ |
+ DEFINE_THREAD_SAFE_STATIC_LOCAL(Mutex, mutex, new Mutex); |
+ return mutex; |
+} |
+ |
+static HashSet<v8::Isolate*>& isolates() |
+{ |
+ DEFINE_STATIC_LOCAL_WITH_LOCK(HashSet<v8::Isolate*>, isolates, ()); |
+ return isolates; |
+} |
+ |
+static void addWorkerIsolate(v8::Isolate* isolate) |
+{ |
+ MutexLocker lock(isolatesMutex()); |
+ isolates().add(isolate); |
+} |
+ |
+static void removeWorkerIsolate(v8::Isolate* isolate) |
+{ |
+ MutexLocker lock(isolatesMutex()); |
+ isolates().remove(isolate); |
+} |
+ |
WorkerBackingThread::WorkerBackingThread(const char* name, bool shouldCallGCOnShutdown) |
: m_backingThread(WebThreadSupportingGC::create(name)) |
, m_isOwningThread(true) |
@@ -63,6 +91,7 @@ void WorkerBackingThread::initialize() |
{ |
DCHECK(!m_isolate); |
m_isolate = V8PerIsolateData::initialize(); |
+ addWorkerIsolate(m_isolate); |
V8Initializer::initializeWorker(m_isolate); |
m_backingThread->initialize(); |
@@ -89,7 +118,17 @@ void WorkerBackingThread::shutdown() |
m_backingThread->shutdown(); |
V8PerIsolateData::destroy(m_isolate); |
+ removeWorkerIsolate(m_isolate); |
jochen (gone - plz use gerrit)
2016/05/04 18:28:14
i suspect this needs to come before V8PerIsolateDa
|
m_isolate = nullptr; |
} |
+// static |
+void WorkerBackingThread::MemoryPressureNotificationToWorkerThreadIsolates( |
+ v8::MemoryPressureLevel level) |
+{ |
+ MutexLocker lock(isolatesMutex()); |
+ for (v8::Isolate* isolate : isolates()) |
+ isolate->MemoryPressureNotification(level); |
+} |
+ |
} // namespace blink |