11cb0ef41Sopenharmony_ci// Copyright 2013 the V8 project authors. All rights reserved.
21cb0ef41Sopenharmony_ci// Use of this source code is governed by a BSD-style license that can be
31cb0ef41Sopenharmony_ci// found in the LICENSE file.
41cb0ef41Sopenharmony_ci
51cb0ef41Sopenharmony_ci#include "src/libplatform/worker-thread.h"
61cb0ef41Sopenharmony_ci
71cb0ef41Sopenharmony_ci#include "include/v8-platform.h"
81cb0ef41Sopenharmony_ci#include "src/libplatform/task-queue.h"
91cb0ef41Sopenharmony_ci
101cb0ef41Sopenharmony_cinamespace v8 {
111cb0ef41Sopenharmony_cinamespace platform {
121cb0ef41Sopenharmony_ci
131cb0ef41Sopenharmony_ciWorkerThread::WorkerThread(TaskQueue* queue)
141cb0ef41Sopenharmony_ci    : Thread(Options("V8 WorkerThread")), queue_(queue) {
151cb0ef41Sopenharmony_ci  CHECK(Start());
161cb0ef41Sopenharmony_ci}
171cb0ef41Sopenharmony_ci
181cb0ef41Sopenharmony_ciWorkerThread::~WorkerThread() {
191cb0ef41Sopenharmony_ci  Join();
201cb0ef41Sopenharmony_ci}
211cb0ef41Sopenharmony_ci
221cb0ef41Sopenharmony_civoid WorkerThread::Run() {
231cb0ef41Sopenharmony_ci  while (std::unique_ptr<Task> task = queue_->GetNext()) {
241cb0ef41Sopenharmony_ci    task->Run();
251cb0ef41Sopenharmony_ci  }
261cb0ef41Sopenharmony_ci}
271cb0ef41Sopenharmony_ci
281cb0ef41Sopenharmony_ci}  // namespace platform
291cb0ef41Sopenharmony_ci}  // namespace v8
30