3
* Copyright 2004--2006, Google Inc.
5
* Redistribution and use in source and binary forms, with or without
6
* modification, are permitted provided that the following conditions are met:
8
* 1. Redistributions of source code must retain the above copyright notice,
9
* this list of conditions and the following disclaimer.
10
* 2. Redistributions in binary form must reproduce the above copyright notice,
11
* this list of conditions and the following disclaimer in the documentation
12
* and/or other materials provided with the distribution.
13
* 3. The name of the author may not be used to endorse or promote products
14
* derived from this software without specific prior written permission.
16
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
17
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
19
* EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
21
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
22
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
23
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
24
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
25
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30
#include "talk/base/taskparent.h"
32
#include "talk/base/task.h"
33
#include "talk/base/taskrunner.h"
37
TaskParent::TaskParent(Task* derived_instance, TaskParent *parent)
39
ASSERT(derived_instance != NULL);
40
ASSERT(parent != NULL);
41
runner_ = parent->GetRunner();
42
parent_->AddChild(derived_instance);
46
TaskParent::TaskParent(TaskRunner *derived_instance)
48
runner_(derived_instance) {
49
ASSERT(derived_instance != NULL);
53
// Does common initialization of member variables
54
void TaskParent::Initialize() {
55
children_.reset(new ChildSet());
59
void TaskParent::AddChild(Task *child) {
60
children_->insert(child);
64
bool TaskParent::IsChildTask(Task *task) {
66
return task->parent_ == this && children_->find(task) != children_->end();
70
bool TaskParent::AllChildrenDone() {
71
for (ChildSet::iterator it = children_->begin();
72
it != children_->end();
80
bool TaskParent::AnyChildError() {
84
void TaskParent::AbortAllChildren() {
85
if (children_->size() > 0) {
87
runner_->IncrementAbortCount();
90
ChildSet copy = *children_;
91
for (ChildSet::iterator it = copy.begin(); it != copy.end(); ++it) {
92
(*it)->Abort(true); // Note we do not wake
96
runner_->DecrementAbortCount();
101
void TaskParent::OnStopped(Task *task) {
103
parent_->OnChildStopped(task);
106
void TaskParent::OnChildStopped(Task *child) {
107
if (child->HasError())
109
children_->erase(child);
112
} // namespace talk_base