task-queue.h 1020 Bytes
Newer Older
1
// Copyright 2013 the V8 project authors. All rights reserved.
2 3
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
4

5 6
#ifndef V8_LIBPLATFORM_TASK_QUEUE_H_
#define V8_LIBPLATFORM_TASK_QUEUE_H_
7

8 9
#include <queue>

10
#include "src/base/macros.h"
11 12
#include "src/base/platform/mutex.h"
#include "src/base/platform/semaphore.h"
13 14

namespace v8 {
15 16 17

class Task;

18
namespace platform {
19

20
class TaskQueue {
21
 public:
22 23 24 25 26
  TaskQueue();
  ~TaskQueue();

  // Appends a task to the queue. The queue takes ownership of |task|.
  void Append(Task* task);
27

28 29 30 31 32 33
  // 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();
34 35

 private:
36 37
  base::Mutex lock_;
  base::Semaphore process_queue_semaphore_;
38 39
  std::queue<Task*> task_queue_;
  bool terminated_;
40

41 42
  DISALLOW_COPY_AND_ASSIGN(TaskQueue);
};
43

44 45
}  // namespace platform
}  // namespace v8
46 47


48
#endif  // V8_LIBPLATFORM_TASK_QUEUE_H_