LCOV - code coverage report
Current view: top level - src/libplatform - task-queue.cc (source / functions) Hit Total Coverage
Test: app.info Lines: 25 25 100.0 %
Date: 2019-01-20 Functions: 6 6 100.0 %

          Line data    Source code
       1             : // Copyright 2013 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/task-queue.h"
       6             : 
       7             : #include "include/v8-platform.h"
       8             : #include "src/base/logging.h"
       9             : #include "src/base/platform/platform.h"
      10             : #include "src/base/platform/time.h"
      11             : 
      12             : namespace v8 {
      13             : namespace platform {
      14             : 
      15      122622 : TaskQueue::TaskQueue() : process_queue_semaphore_(0), terminated_(false) {}
      16             : 
      17             : 
      18      116558 : TaskQueue::~TaskQueue() {
      19       58279 :   base::MutexGuard guard(&lock_);
      20             :   DCHECK(terminated_);
      21             :   DCHECK(task_queue_.empty());
      22       58279 : }
      23             : 
      24     1453444 : void TaskQueue::Append(std::unique_ptr<Task> task) {
      25     1453444 :   base::MutexGuard guard(&lock_);
      26             :   DCHECK(!terminated_);
      27             :   task_queue_.push(std::move(task));
      28     1453444 :   process_queue_semaphore_.Signal();
      29     1453444 : }
      30             : 
      31     1881938 : std::unique_ptr<Task> TaskQueue::GetNext() {
      32             :   for (;;) {
      33             :     {
      34     3615241 :       base::MutexGuard guard(&lock_);
      35     3616774 :       if (!task_queue_.empty()) {
      36             :         std::unique_ptr<Task> result = std::move(task_queue_.front());
      37             :         task_queue_.pop();
      38             :         return result;
      39             :       }
      40     2163330 :       if (terminated_) {
      41      407926 :         process_queue_semaphore_.Signal();
      42             :         return nullptr;
      43             :       }
      44             :     }
      45     1755195 :     process_queue_semaphore_.Wait();
      46     1733303 :   }
      47             : }
      48             : 
      49             : 
      50       58279 : void TaskQueue::Terminate() {
      51       58279 :   base::MutexGuard guard(&lock_);
      52             :   DCHECK(!terminated_);
      53       58279 :   terminated_ = true;
      54       58279 :   process_queue_semaphore_.Signal();
      55       58279 : }
      56             : 
      57           1 : void TaskQueue::BlockUntilQueueEmptyForTesting() {
      58             :   for (;;) {
      59             :     {
      60           2 :       base::MutexGuard guard(&lock_);
      61           3 :       if (task_queue_.empty()) return;
      62             :     }
      63           1 :     base::OS::Sleep(base::TimeDelta::FromMilliseconds(5));
      64           1 :   }
      65             : }
      66             : 
      67             : }  // namespace platform
      68             : }  // namespace v8

Generated by: LCOV version 1.10