Chromium Code Reviews| 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 18fb34ddf42f5fa6ecaf43c43aacd64868c830c8..761d191604c4bab6e9439f7675d0e0ca14146ea1 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() |
| { |
| ASSERT(!m_isolate); |
| m_isolate = V8PerIsolateData::initialize(); |
| + addWorkerIsolate(m_isolate); |
| V8Initializer::initializeWorker(m_isolate); |
| m_backingThread->initialize(); |
| @@ -89,7 +118,20 @@ void WorkerBackingThread::shutdown() |
| m_backingThread->shutdown(); |
| V8PerIsolateData::destroy(m_isolate); |
| + removeWorkerIsolate(m_isolate); |
| m_isolate = nullptr; |
| } |
| +// static |
| +void WorkerBackingThread::MemoryPressureNotificationToWorkerThreadIsolates( |
| + v8::MemoryPressureLevel level) |
| +{ |
| + MutexLocker lock(isolatesMutex()); |
| + for (HashSet<v8::Isolate*>::iterator it = isolates().begin(); |
|
esprehn
2016/04/18 21:57:59
range loop
for (v8::Isolate* isolate : isolates()
hong.zheng
2016/04/19 06:27:43
Done.
|
| + it != isolates().end(); ++it) { |
| + v8::Isolate* isolate = *it; |
| + isolate->MemoryPressureNotification(level); |
| + } |
| +} |
| + |
| } // namespace blink |