2013-11-21 14:07:06 +00:00
|
|
|
// Copyright 2013 the V8 project authors. All rights reserved.
|
2014-04-29 06:42:26 +00:00
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE file.
|
2013-11-21 14:07:06 +00:00
|
|
|
|
2013-12-20 07:52:58 +00:00
|
|
|
#ifndef V8_LIBPLATFORM_TASK_QUEUE_H_
|
|
|
|
#define V8_LIBPLATFORM_TASK_QUEUE_H_
|
2013-11-21 14:07:06 +00:00
|
|
|
|
2013-12-20 07:52:58 +00:00
|
|
|
#include <queue>
|
|
|
|
|
2016-10-10 08:51:48 +00:00
|
|
|
#include "include/libplatform/libplatform-export.h"
|
2014-06-03 08:12:43 +00:00
|
|
|
#include "src/base/macros.h"
|
2014-06-30 13:25:46 +00:00
|
|
|
#include "src/base/platform/mutex.h"
|
|
|
|
#include "src/base/platform/semaphore.h"
|
2016-08-23 11:56:33 +00:00
|
|
|
#include "testing/gtest/include/gtest/gtest_prod.h"
|
2013-11-21 14:07:06 +00:00
|
|
|
|
|
|
|
namespace v8 {
|
2013-12-20 07:52:58 +00:00
|
|
|
|
|
|
|
class Task;
|
|
|
|
|
2014-07-01 08:15:09 +00:00
|
|
|
namespace platform {
|
2013-11-21 14:07:06 +00:00
|
|
|
|
2016-10-10 08:51:48 +00:00
|
|
|
class V8_PLATFORM_EXPORT TaskQueue {
|
2013-11-21 14:07:06 +00:00
|
|
|
public:
|
2013-12-20 07:52:58 +00:00
|
|
|
TaskQueue();
|
|
|
|
~TaskQueue();
|
|
|
|
|
|
|
|
// Appends a task to the queue. The queue takes ownership of |task|.
|
|
|
|
void Append(Task* task);
|
2013-11-21 14:07:06 +00:00
|
|
|
|
2013-12-20 07:52:58 +00:00
|
|
|
// 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();
|
2013-11-21 14:07:06 +00:00
|
|
|
|
|
|
|
private:
|
2016-08-23 11:56:33 +00:00
|
|
|
FRIEND_TEST(WorkerThreadTest, PostSingleTask);
|
|
|
|
|
|
|
|
void BlockUntilQueueEmptyForTesting();
|
|
|
|
|
2014-06-30 13:25:46 +00:00
|
|
|
base::Semaphore process_queue_semaphore_;
|
2016-04-25 18:11:09 +00:00
|
|
|
base::Mutex lock_;
|
2013-12-20 07:52:58 +00:00
|
|
|
std::queue<Task*> task_queue_;
|
|
|
|
bool terminated_;
|
2013-11-21 14:07:06 +00:00
|
|
|
|
2013-12-20 07:52:58 +00:00
|
|
|
DISALLOW_COPY_AND_ASSIGN(TaskQueue);
|
|
|
|
};
|
2013-11-21 14:07:06 +00:00
|
|
|
|
2015-09-30 13:46:56 +00:00
|
|
|
} // namespace platform
|
|
|
|
} // namespace v8
|
2013-11-21 14:07:06 +00:00
|
|
|
|
|
|
|
|
2013-12-20 07:52:58 +00:00
|
|
|
#endif // V8_LIBPLATFORM_TASK_QUEUE_H_
|