1 // Copyright (c) 2010 The Chromium 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.
5 #include "base/task_queue.h"
7 #include "base/logging.h"
8 #include "base/stl_util.h"
10 TaskQueue::TaskQueue() {
13 TaskQueue::~TaskQueue() {
14 // We own all the pointes in |queue_|. It is our job to delete them.
15 STLDeleteElements(&queue_
);
18 void TaskQueue::Push(Task
* task
) {
21 // Add the task to the back of the queue.
22 queue_
.push_back(task
);
25 void TaskQueue::Clear() {
26 // Delete all the elements in the queue and clear the dead pointers.
27 STLDeleteElements(&queue_
);
30 bool TaskQueue::IsEmpty() const {
31 return queue_
.empty();
34 void TaskQueue::Run() {
35 // Nothing to run if our queue is empty.
39 std::deque
<Task
*> ready
;
42 // Run the tasks that are ready.
43 std::deque
<Task
*>::const_iterator task
;
44 for (task
= ready
.begin(); task
!= ready
.end(); ++task
) {
45 // Run the task and then delete it.