| 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 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 188 WorkerThread* m_workerThread; | 188 WorkerThread* m_workerThread; |
| 189 SharedTimerFunction m_sharedTimerFunction; | 189 SharedTimerFunction m_sharedTimerFunction; |
| 190 bool m_running; | 190 bool m_running; |
| 191 | 191 |
| 192 // The task to run OnTimeout, if any. While OnTimeout resets | 192 // The task to run OnTimeout, if any. While OnTimeout resets |
| 193 // m_lastQueuedTask, this must be a weak pointer because the | 193 // m_lastQueuedTask, this must be a weak pointer because the |
| 194 // worker runloop may delete the task as it is shutting down. | 194 // worker runloop may delete the task as it is shutting down. |
| 195 WeakPtr<WorkerThreadCancelableTask> m_lastQueuedTask; | 195 WeakPtr<WorkerThreadCancelableTask> m_lastQueuedTask; |
| 196 }; | 196 }; |
| 197 | 197 |
| 198 class WorkerThreadTask : public blink::WebThread::Task { | 198 class WorkerThreadTask : public WebThread::Task { |
| 199 WTF_MAKE_NONCOPYABLE(WorkerThreadTask); WTF_MAKE_FAST_ALLOCATED(WorkerThread
Task); | 199 WTF_MAKE_NONCOPYABLE(WorkerThreadTask); WTF_MAKE_FAST_ALLOCATED(WorkerThread
Task); |
| 200 public: | 200 public: |
| 201 static PassOwnPtr<WorkerThreadTask> create(WorkerThread& workerThread, PassO
wnPtr<ExecutionContextTask> task, bool isInstrumented) | 201 static PassOwnPtr<WorkerThreadTask> create(WorkerThread& workerThread, PassO
wnPtr<ExecutionContextTask> task, bool isInstrumented) |
| 202 { | 202 { |
| 203 return adoptPtr(new WorkerThreadTask(workerThread, task, isInstrumented)
); | 203 return adoptPtr(new WorkerThreadTask(workerThread, task, isInstrumented)
); |
| 204 } | 204 } |
| 205 | 205 |
| 206 virtual ~WorkerThreadTask() { } | 206 virtual ~WorkerThreadTask() { } |
| 207 | 207 |
| 208 virtual void run() override | 208 virtual void run() override |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 256 WorkerThread* m_thread; | 256 WorkerThread* m_thread; |
| 257 }; | 257 }; |
| 258 | 258 |
| 259 WorkerThread::WorkerThread(const char* threadName, PassRefPtr<WorkerLoaderProxy>
workerLoaderProxy, WorkerReportingProxy& workerReportingProxy, PassOwnPtr<Worke
rThreadStartupData> startupData) | 259 WorkerThread::WorkerThread(const char* threadName, PassRefPtr<WorkerLoaderProxy>
workerLoaderProxy, WorkerReportingProxy& workerReportingProxy, PassOwnPtr<Worke
rThreadStartupData> startupData) |
| 260 : m_threadName(threadName) | 260 : m_threadName(threadName) |
| 261 , m_terminated(false) | 261 , m_terminated(false) |
| 262 , m_workerLoaderProxy(workerLoaderProxy) | 262 , m_workerLoaderProxy(workerLoaderProxy) |
| 263 , m_workerReportingProxy(workerReportingProxy) | 263 , m_workerReportingProxy(workerReportingProxy) |
| 264 , m_startupData(startupData) | 264 , m_startupData(startupData) |
| 265 , m_isolate(nullptr) | 265 , m_isolate(nullptr) |
| 266 , m_shutdownEvent(adoptPtr(blink::Platform::current()->createWaitableEvent()
)) | 266 , m_shutdownEvent(adoptPtr(Platform::current()->createWaitableEvent())) |
| 267 , m_terminationEvent(adoptPtr(blink::Platform::current()->createWaitableEven
t())) | 267 , m_terminationEvent(adoptPtr(Platform::current()->createWaitableEvent())) |
| 268 { | 268 { |
| 269 MutexLocker lock(threadSetMutex()); | 269 MutexLocker lock(threadSetMutex()); |
| 270 workerThreads().add(this); | 270 workerThreads().add(this); |
| 271 } | 271 } |
| 272 | 272 |
| 273 WorkerThread::~WorkerThread() | 273 WorkerThread::~WorkerThread() |
| 274 { | 274 { |
| 275 MutexLocker lock(threadSetMutex()); | 275 MutexLocker lock(threadSetMutex()); |
| 276 ASSERT(workerThreads().contains(this)); | 276 ASSERT(workerThreads().contains(this)); |
| 277 workerThreads().remove(this); | 277 workerThreads().remove(this); |
| (...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 477 terminateV8Execution(); | 477 terminateV8Execution(); |
| 478 | 478 |
| 479 InspectorInstrumentation::didKillAllExecutionContextTasks(m_workerGlobalScop
e.get()); | 479 InspectorInstrumentation::didKillAllExecutionContextTasks(m_workerGlobalScop
e.get()); |
| 480 m_debuggerMessageQueue.kill(); | 480 m_debuggerMessageQueue.kill(); |
| 481 postTask(FROM_HERE, WorkerThreadShutdownStartTask::create()); | 481 postTask(FROM_HERE, WorkerThreadShutdownStartTask::create()); |
| 482 } | 482 } |
| 483 | 483 |
| 484 void WorkerThread::didStartRunLoop() | 484 void WorkerThread::didStartRunLoop() |
| 485 { | 485 { |
| 486 ASSERT(isCurrentThread()); | 486 ASSERT(isCurrentThread()); |
| 487 blink::Platform::current()->didStartWorkerRunLoop(); | 487 Platform::current()->didStartWorkerRunLoop(); |
| 488 } | 488 } |
| 489 | 489 |
| 490 void WorkerThread::didStopRunLoop() | 490 void WorkerThread::didStopRunLoop() |
| 491 { | 491 { |
| 492 ASSERT(isCurrentThread()); | 492 ASSERT(isCurrentThread()); |
| 493 blink::Platform::current()->didStopWorkerRunLoop(); | 493 Platform::current()->didStopWorkerRunLoop(); |
| 494 } | 494 } |
| 495 | 495 |
| 496 void WorkerThread::terminateAndWaitForAllWorkers() | 496 void WorkerThread::terminateAndWaitForAllWorkers() |
| 497 { | 497 { |
| 498 // Keep this lock to prevent WorkerThread instances from being destroyed. | 498 // Keep this lock to prevent WorkerThread instances from being destroyed. |
| 499 MutexLocker lock(threadSetMutex()); | 499 MutexLocker lock(threadSetMutex()); |
| 500 HashSet<WorkerThread*> threads = workerThreads(); | 500 HashSet<WorkerThread*> threads = workerThreads(); |
| 501 for (WorkerThread* thread : threads) | 501 for (WorkerThread* thread : threads) |
| 502 thread->stopInShutdownSequence(); | 502 thread->stopInShutdownSequence(); |
| 503 | 503 |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 576 void WorkerThread::postDebuggerTask(const WebTraceLocation& location, PassOwnPtr
<ExecutionContextTask> task) | 576 void WorkerThread::postDebuggerTask(const WebTraceLocation& location, PassOwnPtr
<ExecutionContextTask> task) |
| 577 { | 577 { |
| 578 m_debuggerMessageQueue.append(WorkerThreadTask::create(*this, task, false)); | 578 m_debuggerMessageQueue.append(WorkerThreadTask::create(*this, task, false)); |
| 579 postTask(location, RunDebuggerQueueTask::create(this)); | 579 postTask(location, RunDebuggerQueueTask::create(this)); |
| 580 } | 580 } |
| 581 | 581 |
| 582 MessageQueueWaitResult WorkerThread::runDebuggerTask(WaitMode waitMode) | 582 MessageQueueWaitResult WorkerThread::runDebuggerTask(WaitMode waitMode) |
| 583 { | 583 { |
| 584 ASSERT(isCurrentThread()); | 584 ASSERT(isCurrentThread()); |
| 585 MessageQueueWaitResult result; | 585 MessageQueueWaitResult result; |
| 586 double absoluteTime = MessageQueue<blink::WebThread::Task>::infiniteTime(); | 586 double absoluteTime = MessageQueue<WebThread::Task>::infiniteTime(); |
| 587 OwnPtr<blink::WebThread::Task> task; | 587 OwnPtr<WebThread::Task> task; |
| 588 { | 588 { |
| 589 if (waitMode == DontWaitForMessage) | 589 if (waitMode == DontWaitForMessage) |
| 590 absoluteTime = 0.0; | 590 absoluteTime = 0.0; |
| 591 SafePointScope safePointScope(ThreadState::NoHeapPointersOnStack); | 591 SafePointScope safePointScope(ThreadState::NoHeapPointersOnStack); |
| 592 task = m_debuggerMessageQueue.waitForMessageWithTimeout(result, absolute
Time); | 592 task = m_debuggerMessageQueue.waitForMessageWithTimeout(result, absolute
Time); |
| 593 } | 593 } |
| 594 | 594 |
| 595 if (result == MessageQueueMessageReceived) { | 595 if (result == MessageQueueMessageReceived) { |
| 596 InspectorInstrumentation::willProcessTask(workerGlobalScope()); | 596 InspectorInstrumentation::willProcessTask(workerGlobalScope()); |
| 597 task->run(); | 597 task->run(); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 611 InspectorInstrumentation::didLeaveNestedRunLoop(m_workerGlobalScope.get()); | 611 InspectorInstrumentation::didLeaveNestedRunLoop(m_workerGlobalScope.get()); |
| 612 } | 612 } |
| 613 | 613 |
| 614 void WorkerThread::setWorkerInspectorController(WorkerInspectorController* worke
rInspectorController) | 614 void WorkerThread::setWorkerInspectorController(WorkerInspectorController* worke
rInspectorController) |
| 615 { | 615 { |
| 616 MutexLocker locker(m_workerInspectorControllerMutex); | 616 MutexLocker locker(m_workerInspectorControllerMutex); |
| 617 m_workerInspectorController = workerInspectorController; | 617 m_workerInspectorController = workerInspectorController; |
| 618 } | 618 } |
| 619 | 619 |
| 620 } // namespace blink | 620 } // namespace blink |
| OLD | NEW |