Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (C) 2008 Apple Inc. All Rights Reserved. | 2 * Copyright (C) 2008 Apple Inc. All Rights Reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
| 6 * are met: | 6 * are met: |
| 7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
| 8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
| 9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
| 10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 47 #include "public/platform/WebScheduler.h" | 47 #include "public/platform/WebScheduler.h" |
| 48 #include "public/platform/WebThread.h" | 48 #include "public/platform/WebThread.h" |
| 49 #include "wtf/Functional.h" | 49 #include "wtf/Functional.h" |
| 50 #include "wtf/Noncopyable.h" | 50 #include "wtf/Noncopyable.h" |
| 51 #include "wtf/WeakPtr.h" | 51 #include "wtf/WeakPtr.h" |
| 52 #include "wtf/text/WTFString.h" | 52 #include "wtf/text/WTFString.h" |
| 53 #include <limits.h> | 53 #include <limits.h> |
| 54 | 54 |
| 55 namespace blink { | 55 namespace blink { |
| 56 | 56 |
| 57 std::set<v8::Isolate*>* WorkerThread::gIsolates = nullptr; | |
| 58 | |
| 57 class WorkerMicrotaskRunner : public WebThread::TaskObserver { | 59 class WorkerMicrotaskRunner : public WebThread::TaskObserver { |
| 58 public: | 60 public: |
| 59 explicit WorkerMicrotaskRunner(WorkerThread* workerThread) | 61 explicit WorkerMicrotaskRunner(WorkerThread* workerThread) |
| 60 : m_workerThread(workerThread) | 62 : m_workerThread(workerThread) |
| 61 { | 63 { |
| 62 } | 64 } |
| 63 | 65 |
| 64 void willProcessTask() override | 66 void willProcessTask() override |
| 65 { | 67 { |
| 66 // No tasks should get executed after we have closed. | 68 // No tasks should get executed after we have closed. |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 203 // Notify the main thread that it is safe to deallocate our resource s. | 205 // Notify the main thread that it is safe to deallocate our resource s. |
| 204 m_terminationEvent->signal(); | 206 m_terminationEvent->signal(); |
| 205 return; | 207 return; |
| 206 } | 208 } |
| 207 | 209 |
| 208 m_microtaskRunner = adoptPtr(new WorkerMicrotaskRunner(this)); | 210 m_microtaskRunner = adoptPtr(new WorkerMicrotaskRunner(this)); |
| 209 initializeBackingThread(); | 211 initializeBackingThread(); |
| 210 backingThread().addTaskObserver(m_microtaskRunner.get()); | 212 backingThread().addTaskObserver(m_microtaskRunner.get()); |
| 211 | 213 |
| 212 m_isolate = initializeIsolate(); | 214 m_isolate = initializeIsolate(); |
| 215 if (!gIsolates) | |
| 216 gIsolates = new std::set<v8::Isolate*>(); | |
| 217 gIsolates->insert(m_isolate); | |
|
kinuko
2016/04/11 09:30:40
For compositor worker (where single thread is shar
hong.zheng
2016/04/15 06:05:57
use WorkerBackingThread instead
| |
| 213 // Optimize for memory usage instead of latency for the worker isolate. | 218 // Optimize for memory usage instead of latency for the worker isolate. |
| 214 m_isolate->IsolateInBackgroundNotification(); | 219 m_isolate->IsolateInBackgroundNotification(); |
| 215 m_workerGlobalScope = createWorkerGlobalScope(startupData); | 220 m_workerGlobalScope = createWorkerGlobalScope(startupData); |
| 216 m_workerGlobalScope->scriptLoaded(sourceCode.length(), cachedMetaData.ge t() ? cachedMetaData->size() : 0); | 221 m_workerGlobalScope->scriptLoaded(sourceCode.length(), cachedMetaData.ge t() ? cachedMetaData->size() : 0); |
| 217 | 222 |
| 218 didStartWorkerThread(); | 223 didStartWorkerThread(); |
| 219 | 224 |
| 220 // Notify proxy that a new WorkerGlobalScope has been created and starte d. | 225 // Notify proxy that a new WorkerGlobalScope has been created and starte d. |
| 221 m_workerReportingProxy.workerGlobalScopeStarted(m_workerGlobalScope.get( )); | 226 m_workerReportingProxy.workerGlobalScopeStarted(m_workerGlobalScope.get( )); |
| 222 | 227 |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 270 // If Oilpan is enabled, we detach of the context/global scope, with the fin al heap cleanup below sweeping it out. | 275 // If Oilpan is enabled, we detach of the context/global scope, with the fin al heap cleanup below sweeping it out. |
| 271 m_workerGlobalScope->notifyContextDestroyed(); | 276 m_workerGlobalScope->notifyContextDestroyed(); |
| 272 #if !ENABLE(OILPAN) | 277 #if !ENABLE(OILPAN) |
| 273 ASSERT(m_workerGlobalScope->hasOneRef()); | 278 ASSERT(m_workerGlobalScope->hasOneRef()); |
| 274 #endif | 279 #endif |
| 275 m_workerGlobalScope = nullptr; | 280 m_workerGlobalScope = nullptr; |
| 276 | 281 |
| 277 willDestroyIsolate(); | 282 willDestroyIsolate(); |
| 278 shutdownBackingThread(); | 283 shutdownBackingThread(); |
| 279 destroyIsolate(); | 284 destroyIsolate(); |
| 285 gIsolates->erase(m_isolate); | |
| 280 m_isolate = nullptr; | 286 m_isolate = nullptr; |
| 281 | 287 |
| 282 m_microtaskRunner = nullptr; | 288 m_microtaskRunner = nullptr; |
| 283 | 289 |
| 284 // Notify the proxy that the WorkerGlobalScope has been disposed of. | 290 // Notify the proxy that the WorkerGlobalScope has been disposed of. |
| 285 // This can free this thread object, hence it must not be touched afterwards . | 291 // This can free this thread object, hence it must not be touched afterwards . |
| 286 workerReportingProxy().workerThreadTerminated(); | 292 workerReportingProxy().workerThreadTerminated(); |
| 287 | 293 |
| 288 m_terminationEvent->signal(); | 294 m_terminationEvent->signal(); |
| 289 } | 295 } |
| (...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 494 // Keep waiting until execution is resumed. | 500 // Keep waiting until execution is resumed. |
| 495 } while (task && m_pausedInDebugger); | 501 } while (task && m_pausedInDebugger); |
| 496 InspectorInstrumentation::didLeaveNestedRunLoop(m_workerGlobalScope.get()); | 502 InspectorInstrumentation::didLeaveNestedRunLoop(m_workerGlobalScope.get()); |
| 497 } | 503 } |
| 498 | 504 |
| 499 void WorkerThread::stopRunningDebuggerTasksOnPause() | 505 void WorkerThread::stopRunningDebuggerTasksOnPause() |
| 500 { | 506 { |
| 501 m_pausedInDebugger = false; | 507 m_pausedInDebugger = false; |
| 502 } | 508 } |
| 503 | 509 |
| 510 // static | |
| 511 std::set<v8::Isolate*>* WorkerThread::workerThreadIsolates() | |
| 512 { | |
| 513 return gIsolates; | |
|
kinuko
2016/04/11 09:30:40
We seem to be accessing this set from multiple thr
hong.zheng
2016/04/15 06:05:57
Done.
| |
| 514 } | |
| 515 | |
| 504 } // namespace blink | 516 } // namespace blink |
| OLD | NEW |