ipc/chromium/src/chrome/common/task_queue.cc

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
michael@0 2 // Use of this source code is governed by a BSD-style license that can be
michael@0 3 // found in the LICENSE file.
michael@0 4
michael@0 5 #include "chrome/common/task_queue.h"
michael@0 6
michael@0 7 #include "base/stl_util-inl.h"
michael@0 8
michael@0 9 TaskQueue::TaskQueue() {
michael@0 10 }
michael@0 11
michael@0 12 TaskQueue::~TaskQueue() {
michael@0 13 // We own all the pointes in |queue_|. It is our job to delete them.
michael@0 14 STLDeleteElements(&queue_);
michael@0 15 }
michael@0 16
michael@0 17 void TaskQueue::Run() {
michael@0 18 // Nothing to run if our queue is empty.
michael@0 19 if (queue_.empty())
michael@0 20 return;
michael@0 21
michael@0 22 std::deque<Task*> ready;
michael@0 23 queue_.swap(ready);
michael@0 24
michael@0 25 // Run the tasks that are ready.
michael@0 26 std::deque<Task*>::const_iterator task;
michael@0 27 for (task = ready.begin(); task != ready.end(); ++task) {
michael@0 28 // Run the task and then delete it.
michael@0 29 (*task)->Run();
michael@0 30 delete (*task);
michael@0 31 }
michael@0 32 }
michael@0 33
michael@0 34 void TaskQueue::Push(Task* task) {
michael@0 35 // Add the task to the back of the queue.
michael@0 36 queue_.push_back(task);
michael@0 37 }
michael@0 38
michael@0 39 void TaskQueue::Clear() {
michael@0 40 // Delete all the elements in the queue and clear the dead pointers.
michael@0 41 STLDeleteElements(&queue_);
michael@0 42 }
michael@0 43
michael@0 44 bool TaskQueue::Empty() const {
michael@0 45 return queue_.empty();
michael@0 46 }

mercurial