LCOV - code coverage report
Current view: top level - src/libplatform - default-worker-threads-task-runner.cc (source / functions) Hit Total Coverage
Test: app.info Lines: 22 27 81.5 %
Date: 2019-01-20 Functions: 5 8 62.5 %

          Line data    Source code
       1             : // Copyright 2017 the V8 project authors. All rights reserved.
       2             : // Use of this source code is governed by a BSD-style license that can be
       3             : // found in the LICENSE file.
       4             : 
       5             : #include "src/libplatform/default-worker-threads-task-runner.h"
       6             : 
       7             : #include "src/base/platform/mutex.h"
       8             : #include "src/libplatform/worker-thread.h"
       9             : 
      10             : namespace v8 {
      11             : namespace platform {
      12             : 
      13       61307 : DefaultWorkerThreadsTaskRunner::DefaultWorkerThreadsTaskRunner(
      14       61307 :     uint32_t thread_pool_size) {
      15      490450 :   for (uint32_t i = 0; i < thread_pool_size; ++i) {
      16      858286 :     thread_pool_.push_back(base::make_unique<WorkerThread>(&queue_));
      17             :   }
      18       61307 : }
      19             : 
      20             : // NOLINTNEXTLINE
      21       58275 : DefaultWorkerThreadsTaskRunner::~DefaultWorkerThreadsTaskRunner() {
      22             :   // This destructor is needed because we have unique_ptr to the WorkerThreads,
      23             :   // und the {WorkerThread} class is forward declared in the header file.
      24       58275 : }
      25             : 
      26       58275 : void DefaultWorkerThreadsTaskRunner::Terminate() {
      27       58275 :   base::MutexGuard guard(&lock_);
      28       58275 :   terminated_ = true;
      29       58275 :   queue_.Terminate();
      30             :   // Clearing the thread pool lets all worker threads join.
      31             :   thread_pool_.clear();
      32       58275 : }
      33             : 
      34     1453402 : void DefaultWorkerThreadsTaskRunner::PostTask(std::unique_ptr<Task> task) {
      35     1453402 :   base::MutexGuard guard(&lock_);
      36     2906804 :   if (terminated_) return;
      37     2906804 :   queue_.Append(std::move(task));
      38             : }
      39             : 
      40          30 : void DefaultWorkerThreadsTaskRunner::PostDelayedTask(std::unique_ptr<Task> task,
      41             :                                                      double delay_in_seconds) {
      42          30 :   base::MutexGuard guard(&lock_);
      43          30 :   if (terminated_) return;
      44          30 :   if (delay_in_seconds == 0) {
      45          60 :     queue_.Append(std::move(task));
      46          30 :     return;
      47             :   }
      48             :   // There is no use case for this function with non zero delay_in_second on a
      49             :   // worker thread at the moment, but it is still part of the interface.
      50           0 :   UNIMPLEMENTED();
      51             : }
      52             : 
      53           0 : void DefaultWorkerThreadsTaskRunner::PostIdleTask(
      54             :     std::unique_ptr<IdleTask> task) {
      55             :   // There are no idle worker tasks.
      56           0 :   UNREACHABLE();
      57             : }
      58             : 
      59           0 : bool DefaultWorkerThreadsTaskRunner::IdleTasksEnabled() {
      60             :   // There are no idle worker tasks.
      61           0 :   return false;
      62             : }
      63             : 
      64             : }  // namespace platform
      65             : }  // namespace v8

Generated by: LCOV version 1.10