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 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 157 // ensure none of those are ran. | 157 // ensure none of those are ran. |
| 158 if (!workerGlobalScope) | 158 if (!workerGlobalScope) |
| 159 return; | 159 return; |
| 160 | 160 |
| 161 if (m_isInstrumented) | 161 if (m_isInstrumented) |
| 162 InspectorInstrumentation::willPerformExecutionContextTask(workerGlob alScope, m_task.get()); | 162 InspectorInstrumentation::willPerformExecutionContextTask(workerGlob alScope, m_task.get()); |
| 163 if ((!workerGlobalScope->isClosing() && !m_workerThread.terminated()) || m_task->isCleanupTask()) | 163 if ((!workerGlobalScope->isClosing() && !m_workerThread.terminated()) || m_task->isCleanupTask()) |
| 164 m_task->performTask(workerGlobalScope); | 164 m_task->performTask(workerGlobalScope); |
| 165 if (m_isInstrumented) | 165 if (m_isInstrumented) |
| 166 InspectorInstrumentation::didPerformExecutionContextTask(workerGloba lScope); | 166 InspectorInstrumentation::didPerformExecutionContextTask(workerGloba lScope); |
| 167 | |
| 168 // If no more tasks are queued up after this, then queue up the idleHand ler | |
| 169 // to trigger GC. | |
| 170 WorkerThread& workerThread = const_cast<WorkerThread&>(m_workerThread); | |
| 171 if (!workerThread.decrementAndReturnTaskCount() && !workerThread.isIdleH andlerTaskFiredOnce()) | |
|
jochen (gone - plz use gerrit)
2014/09/02 10:14:14
maybe teach WorkerThreadTask that it's an idle tas
Mayur Kankanwadi
2014/09/03 11:26:21
Done.
| |
| 172 workerThread.queueUpIdleHandlerNow(); | |
| 167 } | 173 } |
| 168 | 174 |
| 169 private: | 175 private: |
| 170 WorkerThreadTask(const WorkerThread& workerThread, PassOwnPtr<ExecutionConte xtTask> task, bool isInstrumented) | 176 WorkerThreadTask(const WorkerThread& workerThread, PassOwnPtr<ExecutionConte xtTask> task, bool isInstrumented) |
| 171 : m_workerThread(workerThread) | 177 : m_workerThread(workerThread) |
| 172 , m_task(task) | 178 , m_task(task) |
| 173 , m_isInstrumented(isInstrumented) | 179 , m_isInstrumented(isInstrumented) |
| 174 { | 180 { |
| 175 if (m_isInstrumented) | 181 if (m_isInstrumented) |
| 176 m_isInstrumented = !m_task->taskNameForInstrumentation().isEmpty(); | 182 m_isInstrumented = !m_task->taskNameForInstrumentation().isEmpty(); |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 200 | 206 |
| 201 WorkerThread* m_thread; | 207 WorkerThread* m_thread; |
| 202 }; | 208 }; |
| 203 | 209 |
| 204 WorkerThread::WorkerThread(WorkerLoaderProxy& workerLoaderProxy, WorkerReporting Proxy& workerReportingProxy, PassOwnPtrWillBeRawPtr<WorkerThreadStartupData> sta rtupData) | 210 WorkerThread::WorkerThread(WorkerLoaderProxy& workerLoaderProxy, WorkerReporting Proxy& workerReportingProxy, PassOwnPtrWillBeRawPtr<WorkerThreadStartupData> sta rtupData) |
| 205 : m_terminated(false) | 211 : m_terminated(false) |
| 206 , m_workerLoaderProxy(workerLoaderProxy) | 212 , m_workerLoaderProxy(workerLoaderProxy) |
| 207 , m_workerReportingProxy(workerReportingProxy) | 213 , m_workerReportingProxy(workerReportingProxy) |
| 208 , m_startupData(startupData) | 214 , m_startupData(startupData) |
| 209 , m_shutdownEvent(adoptPtr(blink::Platform::current()->createWaitableEvent() )) | 215 , m_shutdownEvent(adoptPtr(blink::Platform::current()->createWaitableEvent() )) |
| 216 , m_tasksCount(0) | |
| 217 , m_isIdleHandlerTaskFiredOnce(false) | |
| 218 , m_isIdleHandlerTask(false) | |
| 210 { | 219 { |
| 211 MutexLocker lock(threadSetMutex()); | 220 MutexLocker lock(threadSetMutex()); |
| 212 workerThreads().add(this); | 221 workerThreads().add(this); |
| 213 } | 222 } |
| 214 | 223 |
| 215 WorkerThread::~WorkerThread() | 224 WorkerThread::~WorkerThread() |
| 216 { | 225 { |
| 217 MutexLocker lock(threadSetMutex()); | 226 MutexLocker lock(threadSetMutex()); |
| 218 ASSERT(workerThreads().contains(this)); | 227 ASSERT(workerThreads().contains(this)); |
| 219 workerThreads().remove(this); | 228 workerThreads().remove(this); |
| (...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 395 InspectorInstrumentation::didKillAllExecutionContextTasks(m_workerGlobalScop e.get()); | 404 InspectorInstrumentation::didKillAllExecutionContextTasks(m_workerGlobalScop e.get()); |
| 396 m_debuggerMessageQueue.kill(); | 405 m_debuggerMessageQueue.kill(); |
| 397 postTask(WorkerThreadShutdownStartTask::create()); | 406 postTask(WorkerThreadShutdownStartTask::create()); |
| 398 } | 407 } |
| 399 | 408 |
| 400 bool WorkerThread::isCurrentThread() const | 409 bool WorkerThread::isCurrentThread() const |
| 401 { | 410 { |
| 402 return m_thread && m_thread->isCurrentThread(); | 411 return m_thread && m_thread->isCurrentThread(); |
| 403 } | 412 } |
| 404 | 413 |
| 414 bool WorkerThread::isIdleHandlerTaskFiredOnce() | |
| 415 { | |
| 416 MutexLocker lock(m_taskCounterMutex); | |
| 417 return m_isIdleHandlerTaskFiredOnce; | |
| 418 } | |
| 419 | |
| 420 void WorkerThread::queueUpIdleHandlerNow() | |
| 421 { | |
| 422 m_isIdleHandlerTask = m_isIdleHandlerTaskFiredOnce = true; | |
| 423 postTask(createSameThreadTask(&WorkerThread::idleHandler, this)); | |
| 424 m_isIdleHandlerTask = false; | |
|
jochen (gone - plz use gerrit)
2014/09/02 10:14:14
instead of using m_isIdleHandlerTask, this method
Mayur Kankanwadi
2014/09/03 11:26:21
Done.
| |
| 425 } | |
| 426 | |
| 405 void WorkerThread::idleHandler() | 427 void WorkerThread::idleHandler() |
| 406 { | 428 { |
| 407 ASSERT(m_workerGlobalScope.get()); | 429 ASSERT(m_workerGlobalScope.get()); |
| 408 int64 delay = kLongIdleHandlerDelayMs; | 430 int64 delay = kLongIdleHandlerDelayMs; |
| 409 | 431 |
| 410 // Do a script engine idle notification if the next event is distant enough. | 432 // Do a script engine idle notification if the next event is distant enough. |
| 411 const double kMinIdleTimespan = 0.3; | 433 const double kMinIdleTimespan = 0.3; |
| 434 // This is set to true when idleNotification returns false. | |
| 435 // idleNotification returns false only when more GC is required. It returns | |
| 436 // true if no more GC is required and that is when callGCAgain will be set t o false. | |
| 437 bool callGCAgain = false; | |
| 412 if (m_sharedTimer->nextFireTime() == 0.0 || m_sharedTimer->nextFireTime() > currentTime() + kMinIdleTimespan) { | 438 if (m_sharedTimer->nextFireTime() == 0.0 || m_sharedTimer->nextFireTime() > currentTime() + kMinIdleTimespan) { |
| 413 bool hasMoreWork = !m_workerGlobalScope->idleNotification(); | 439 bool callGCAgain = !m_workerGlobalScope->idleNotification(); |
|
Mayur Kankanwadi
2014/09/03 11:26:21
This(bool callGCAgain) was an extra definition, wi
| |
| 414 if (hasMoreWork) | 440 if (callGCAgain) |
| 415 delay = kShortIdleHandlerDelayMs; | 441 delay = kShortIdleHandlerDelayMs; |
| 416 } | 442 } |
| 443 if (callGCAgain) { | |
| 444 postDelayedTask(createSameThreadTask(&WorkerThread::idleHandler, this), delay); | |
| 445 } | |
| 446 } | |
| 417 | 447 |
| 418 postDelayedTask(createSameThreadTask(&WorkerThread::idleHandler, this), dela y); | 448 void WorkerThread::decrementTaskCount() |
|
jochen (gone - plz use gerrit)
2014/09/02 10:14:14
this method isn't used anywhere?
Mayur Kankanwadi
2014/09/03 11:26:22
True.Removed it.
| |
| 449 { | |
| 450 MutexLocker lock(m_taskCounterMutex); | |
| 451 if (!m_tasksCount) | |
| 452 return; | |
| 453 --m_tasksCount; | |
| 454 } | |
| 455 | |
| 456 unsigned WorkerThread::decrementAndReturnTaskCount() | |
| 457 { | |
| 458 MutexLocker lock(m_taskCounterMutex); | |
| 459 if (!m_tasksCount) | |
|
jochen (gone - plz use gerrit)
2014/09/02 10:14:14
see my comment about not invoking this for idle ta
Mayur Kankanwadi
2014/09/03 11:26:21
Done.
| |
| 460 return 0; | |
| 461 --m_tasksCount; | |
| 462 return m_tasksCount; | |
| 463 } | |
| 464 | |
| 465 unsigned WorkerThread::taskCount() | |
|
jochen (gone - plz use gerrit)
2014/09/02 10:14:14
not used anywhere?
Mayur Kankanwadi
2014/09/03 11:26:22
True.Removed it.
| |
| 466 { | |
| 467 MutexLocker lock(m_taskCounterMutex); | |
| 468 return m_tasksCount; | |
| 419 } | 469 } |
| 420 | 470 |
| 421 void WorkerThread::postTask(PassOwnPtr<ExecutionContextTask> task) | 471 void WorkerThread::postTask(PassOwnPtr<ExecutionContextTask> task) |
| 422 { | 472 { |
| 473 if (!m_isIdleHandlerTask) { | |
| 474 MutexLocker lock(m_taskCounterMutex); | |
| 475 ++m_tasksCount; | |
| 476 m_isIdleHandlerTaskFiredOnce = false; | |
| 477 } | |
| 423 m_thread->postTask(WorkerThreadTask::create(*this, task, true).leakPtr()); | 478 m_thread->postTask(WorkerThreadTask::create(*this, task, true).leakPtr()); |
| 424 } | 479 } |
| 425 | 480 |
| 426 void WorkerThread::postDelayedTask(PassOwnPtr<ExecutionContextTask> task, long l ong delayMs) | 481 void WorkerThread::postDelayedTask(PassOwnPtr<ExecutionContextTask> task, long l ong delayMs) |
| 427 { | 482 { |
| 483 if (!m_isIdleHandlerTask) { | |
| 484 MutexLocker lock(m_taskCounterMutex); | |
| 485 ++m_tasksCount; | |
| 486 m_isIdleHandlerTaskFiredOnce = false; | |
| 487 } | |
| 428 m_thread->postDelayedTask(WorkerThreadTask::create(*this, task, true).leakPt r(), delayMs); | 488 m_thread->postDelayedTask(WorkerThreadTask::create(*this, task, true).leakPt r(), delayMs); |
| 429 } | 489 } |
| 430 | 490 |
| 431 void WorkerThread::postDebuggerTask(PassOwnPtr<ExecutionContextTask> task) | 491 void WorkerThread::postDebuggerTask(PassOwnPtr<ExecutionContextTask> task) |
| 432 { | 492 { |
| 433 m_debuggerMessageQueue.append(WorkerThreadTask::create(*this, task, false)); | 493 m_debuggerMessageQueue.append(WorkerThreadTask::create(*this, task, false)); |
| 434 postTask(RunDebuggerQueueTask::create(this)); | 494 postTask(RunDebuggerQueueTask::create(this)); |
| 435 } | 495 } |
| 436 | 496 |
| 437 MessageQueueWaitResult WorkerThread::runDebuggerTask(WaitMode waitMode) | 497 MessageQueueWaitResult WorkerThread::runDebuggerTask(WaitMode waitMode) |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 466 InspectorInstrumentation::didLeaveNestedRunLoop(m_workerGlobalScope.get()); | 526 InspectorInstrumentation::didLeaveNestedRunLoop(m_workerGlobalScope.get()); |
| 467 } | 527 } |
| 468 | 528 |
| 469 void WorkerThread::setWorkerInspectorController(WorkerInspectorController* worke rInspectorController) | 529 void WorkerThread::setWorkerInspectorController(WorkerInspectorController* worke rInspectorController) |
| 470 { | 530 { |
| 471 MutexLocker locker(m_workerInspectorControllerMutex); | 531 MutexLocker locker(m_workerInspectorControllerMutex); |
| 472 m_workerInspectorController = workerInspectorController; | 532 m_workerInspectorController = workerInspectorController; |
| 473 } | 533 } |
| 474 | 534 |
| 475 } // namespace blink | 535 } // namespace blink |
| OLD | NEW |