c59cf8cd21
BUG=v8:5412 R=jgruber@chromium.org,machenbach@chromium.org CQ_INCLUDE_TRYBOTS=master.tryserver.chromium.linux:linux_chromium_compile_dbg_ng;master.tryserver.chromium.android:android_clang_dbg_recipe Review-Url: https://codereview.chromium.org/2372983003 Cr-Commit-Position: refs/heads/master@{#40111}
55 lines
1.2 KiB
C++
55 lines
1.2 KiB
C++
// Copyright 2013 the V8 project authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
// found in the LICENSE file.
|
|
|
|
#ifndef V8_LIBPLATFORM_TASK_QUEUE_H_
|
|
#define V8_LIBPLATFORM_TASK_QUEUE_H_
|
|
|
|
#include <queue>
|
|
|
|
#include "include/libplatform/libplatform-export.h"
|
|
#include "src/base/macros.h"
|
|
#include "src/base/platform/mutex.h"
|
|
#include "src/base/platform/semaphore.h"
|
|
#include "testing/gtest/include/gtest/gtest_prod.h"
|
|
|
|
namespace v8 {
|
|
|
|
class Task;
|
|
|
|
namespace platform {
|
|
|
|
class V8_PLATFORM_EXPORT TaskQueue {
|
|
public:
|
|
TaskQueue();
|
|
~TaskQueue();
|
|
|
|
// Appends a task to the queue. The queue takes ownership of |task|.
|
|
void Append(Task* task);
|
|
|
|
// Returns the next task to process. Blocks if no task is available. Returns
|
|
// NULL if the queue is terminated.
|
|
Task* GetNext();
|
|
|
|
// Terminate the queue.
|
|
void Terminate();
|
|
|
|
private:
|
|
FRIEND_TEST(WorkerThreadTest, PostSingleTask);
|
|
|
|
void BlockUntilQueueEmptyForTesting();
|
|
|
|
base::Semaphore process_queue_semaphore_;
|
|
base::Mutex lock_;
|
|
std::queue<Task*> task_queue_;
|
|
bool terminated_;
|
|
|
|
DISALLOW_COPY_AND_ASSIGN(TaskQueue);
|
|
};
|
|
|
|
} // namespace platform
|
|
} // namespace v8
|
|
|
|
|
|
#endif // V8_LIBPLATFORM_TASK_QUEUE_H_
|