diff options
author | levin@chromium.org <levin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-08-26 06:09:38 +0000 |
---|---|---|
committer | levin@chromium.org <levin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-08-26 06:09:38 +0000 |
commit | 6fd0ca52fbb5d33e3355c0ebe8fe81219be90de0 (patch) | |
tree | 6a24baf9874440f81fde368ab964ffc0d912c2d5 /base/task_queue.cc | |
parent | b924ae04055aa82cd19ef522b690e3cd66352c11 (diff) | |
download | chromium_src-6fd0ca52fbb5d33e3355c0ebe8fe81219be90de0.zip chromium_src-6fd0ca52fbb5d33e3355c0ebe8fe81219be90de0.tar.gz chromium_src-6fd0ca52fbb5d33e3355c0ebe8fe81219be90de0.tar.bz2 |
Move task_queue.* to base because it makes more sense there.
TEST=base_test --gtest_filter=TaskQueue*.* (added in this patch).
BUG=38475
Review URL: http://codereview.chromium.org/3205004
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@57479 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/task_queue.cc')
-rw-r--r-- | base/task_queue.cc | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/base/task_queue.cc b/base/task_queue.cc new file mode 100644 index 0000000..e3c196b --- /dev/null +++ b/base/task_queue.cc @@ -0,0 +1,49 @@ +// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "base/task_queue.h" + +#include "base/logging.h" +#include "base/stl_util-inl.h" + +TaskQueue::TaskQueue() { +} + +TaskQueue::~TaskQueue() { + // We own all the pointes in |queue_|. It is our job to delete them. + STLDeleteElements(&queue_); +} + +void TaskQueue::Run() { + // Nothing to run if our queue is empty. + if (queue_.empty()) + return; + + std::deque<Task*> ready; + queue_.swap(ready); + + // Run the tasks that are ready. + std::deque<Task*>::const_iterator task; + for (task = ready.begin(); task != ready.end(); ++task) { + // Run the task and then delete it. + (*task)->Run(); + delete (*task); + } +} + +void TaskQueue::Push(Task* task) { + DCHECK(task); + + // Add the task to the back of the queue. + queue_.push_back(task); +} + +void TaskQueue::Clear() { + // Delete all the elements in the queue and clear the dead pointers. + STLDeleteElements(&queue_); +} + +bool TaskQueue::IsEmpty() const { + return queue_.empty(); +} |