Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(147)

Side by Side Diff: webrtc/base/taskparent.cc

Issue 2620303003: Replace ASSERT by RTC_DCHECK in all non-test code. (Closed)
Patch Set: Address final nits. Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « webrtc/base/taskparent.h ('k') | webrtc/base/taskrunner.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2004 The WebRTC Project Authors. All rights reserved. 2 * Copyright 2004 The WebRTC Project Authors. All rights reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source 5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
11 #include <algorithm> 11 #include <algorithm>
12 12
13 #include "webrtc/base/taskparent.h" 13 #include "webrtc/base/taskparent.h"
14 14
15 #include "webrtc/base/checks.h"
15 #include "webrtc/base/common.h" 16 #include "webrtc/base/common.h"
16 #include "webrtc/base/task.h" 17 #include "webrtc/base/task.h"
17 #include "webrtc/base/taskrunner.h" 18 #include "webrtc/base/taskrunner.h"
18 19
19 namespace rtc { 20 namespace rtc {
20 21
21 TaskParent::TaskParent(Task* derived_instance, TaskParent *parent) 22 TaskParent::TaskParent(Task* derived_instance, TaskParent *parent)
22 : parent_(parent) { 23 : parent_(parent) {
23 ASSERT(derived_instance != NULL); 24 RTC_DCHECK(derived_instance != NULL);
24 ASSERT(parent != NULL); 25 RTC_DCHECK(parent != NULL);
25 runner_ = parent->GetRunner(); 26 runner_ = parent->GetRunner();
26 parent_->AddChild(derived_instance); 27 parent_->AddChild(derived_instance);
27 Initialize(); 28 Initialize();
28 } 29 }
29 30
30 TaskParent::TaskParent(TaskRunner *derived_instance) 31 TaskParent::TaskParent(TaskRunner *derived_instance)
31 : parent_(NULL), 32 : parent_(NULL),
32 runner_(derived_instance) { 33 runner_(derived_instance) {
33 ASSERT(derived_instance != NULL); 34 RTC_DCHECK(derived_instance != NULL);
34 Initialize(); 35 Initialize();
35 } 36 }
36 37
37 TaskParent::~TaskParent() = default; 38 TaskParent::~TaskParent() = default;
38 39
39 // Does common initialization of member variables 40 // Does common initialization of member variables
40 void TaskParent::Initialize() { 41 void TaskParent::Initialize() {
41 children_.reset(new ChildSet()); 42 children_.reset(new ChildSet());
42 child_error_ = false; 43 child_error_ = false;
43 } 44 }
44 45
45 void TaskParent::AddChild(Task *child) { 46 void TaskParent::AddChild(Task *child) {
46 children_->insert(child); 47 children_->insert(child);
47 } 48 }
48 49
49 #if !defined(NDEBUG) 50 #if RTC_DCHECK_IS_ON
50 bool TaskParent::IsChildTask(Task *task) { 51 bool TaskParent::IsChildTask(Task *task) {
51 ASSERT(task != NULL); 52 RTC_DCHECK(task != NULL);
52 return task->parent_ == this && children_->find(task) != children_->end(); 53 return task->parent_ == this && children_->find(task) != children_->end();
53 } 54 }
54 #endif 55 #endif
55 56
56 bool TaskParent::AllChildrenDone() { 57 bool TaskParent::AllChildrenDone() {
57 for (ChildSet::iterator it = children_->begin(); 58 for (ChildSet::iterator it = children_->begin();
58 it != children_->end(); 59 it != children_->end();
59 ++it) { 60 ++it) {
60 if (!(*it)->IsDone()) 61 if (!(*it)->IsDone())
61 return false; 62 return false;
62 } 63 }
63 return true; 64 return true;
64 } 65 }
65 66
66 bool TaskParent::AnyChildError() { 67 bool TaskParent::AnyChildError() {
67 return child_error_; 68 return child_error_;
68 } 69 }
69 70
70 void TaskParent::AbortAllChildren() { 71 void TaskParent::AbortAllChildren() {
71 if (children_->size() > 0) { 72 if (children_->size() > 0) {
72 #if !defined(NDEBUG) 73 #if RTC_DCHECK_IS_ON
73 runner_->IncrementAbortCount(); 74 runner_->IncrementAbortCount();
74 #endif 75 #endif
75 76
76 ChildSet copy = *children_; 77 ChildSet copy = *children_;
77 for (ChildSet::iterator it = copy.begin(); it != copy.end(); ++it) { 78 for (ChildSet::iterator it = copy.begin(); it != copy.end(); ++it) {
78 (*it)->Abort(true); // Note we do not wake 79 (*it)->Abort(true); // Note we do not wake
79 } 80 }
80 81
81 #if !defined(NDEBUG) 82 #if RTC_DCHECK_IS_ON
82 runner_->DecrementAbortCount(); 83 runner_->DecrementAbortCount();
83 #endif 84 #endif
84 } 85 }
85 } 86 }
86 87
87 void TaskParent::OnStopped(Task *task) { 88 void TaskParent::OnStopped(Task *task) {
88 AbortAllChildren(); 89 AbortAllChildren();
89 parent_->OnChildStopped(task); 90 parent_->OnChildStopped(task);
90 } 91 }
91 92
92 void TaskParent::OnChildStopped(Task *child) { 93 void TaskParent::OnChildStopped(Task *child) {
93 if (child->HasError()) 94 if (child->HasError())
94 child_error_ = true; 95 child_error_ = true;
95 children_->erase(child); 96 children_->erase(child);
96 } 97 }
97 98
98 } // namespace rtc 99 } // namespace rtc
OLDNEW
« no previous file with comments | « webrtc/base/taskparent.h ('k') | webrtc/base/taskrunner.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698