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

Side by Side Diff: base/task_scheduler/scheduler_lock_impl.cc

Issue 2213933003: Change EXPECT/ASSERT_DCHECK_DEATH macro to not expose the |regex| parameter. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@b2b0_simplethreadJoinable
Patch Set: Fix SchedulerLock unittests to actually generate a DCHECK, not an exception Created 4 years, 4 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
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/task_scheduler/scheduler_lock_impl.h" 5 #include "base/task_scheduler/scheduler_lock_impl.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <unordered_map> 8 #include <unordered_map>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
60 void AssertSafeAcquire(const SchedulerLockImpl* const lock) { 60 void AssertSafeAcquire(const SchedulerLockImpl* const lock) {
61 const LockVector* acquired_locks = GetAcquiredLocksOnCurrentThread(); 61 const LockVector* acquired_locks = GetAcquiredLocksOnCurrentThread();
62 62
63 // If the thread currently holds no locks, this is inherently safe. 63 // If the thread currently holds no locks, this is inherently safe.
64 if (acquired_locks->empty()) 64 if (acquired_locks->empty())
65 return; 65 return;
66 66
67 // Otherwise, make sure that the previous lock acquired is an allowed 67 // Otherwise, make sure that the previous lock acquired is an allowed
68 // predecessor. 68 // predecessor.
69 AutoLock auto_lock(allowed_predecessor_map_lock_); 69 AutoLock auto_lock(allowed_predecessor_map_lock_);
70 // Using at() is exception-safe here as |lock| was registered already.
70 const SchedulerLockImpl* allowed_predecessor = 71 const SchedulerLockImpl* allowed_predecessor =
71 allowed_predecessor_map_.at(lock); 72 allowed_predecessor_map_.at(lock);
72 DCHECK_EQ(acquired_locks->back(), allowed_predecessor); 73 DCHECK_EQ(acquired_locks->back(), allowed_predecessor);
73 } 74 }
74 75
76 // This asserts that lock's registered predecessor is safe. Since registration
robliao 2016/08/04 17:25:20 This change should be pulled out of this CL. Nice
gab 2016/08/04 17:43:05 Done: https://codereview.chromium.org/2218443002/
77 // only happens at construction time, the predecessor is safe (no cycle
78 // possible) as long as it is either null or already registered.
75 void AssertSafePredecessor(const SchedulerLockImpl* lock) const { 79 void AssertSafePredecessor(const SchedulerLockImpl* lock) const {
76 allowed_predecessor_map_lock_.AssertAcquired(); 80 allowed_predecessor_map_lock_.AssertAcquired();
77 for (const SchedulerLockImpl* predecessor = 81 // Using at() is exception-safe here as |lock| was registered already.
78 allowed_predecessor_map_.at(lock); 82 const SchedulerLockImpl* predecessor = allowed_predecessor_map_.at(lock);
79 predecessor != nullptr; 83 if (predecessor) {
80 predecessor = allowed_predecessor_map_.at(predecessor)) { 84 DCHECK(allowed_predecessor_map_.find(predecessor) !=
81 DCHECK_NE(predecessor, lock) << 85 allowed_predecessor_map_.end())
82 "Scheduler lock predecessor cycle detected."; 86 << "SchedulerLock was registered before its predecessor. "
87 << "Potential cycle detected";
83 } 88 }
84 } 89 }
85 90
86 LockVector* GetAcquiredLocksOnCurrentThread() { 91 LockVector* GetAcquiredLocksOnCurrentThread() {
87 if (!tls_acquired_locks_.Get()) 92 if (!tls_acquired_locks_.Get())
88 tls_acquired_locks_.Set(new LockVector); 93 tls_acquired_locks_.Set(new LockVector);
89 94
90 return reinterpret_cast<LockVector*>(tls_acquired_locks_.Get()); 95 return reinterpret_cast<LockVector*>(tls_acquired_locks_.Get());
91 } 96 }
92 97
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
136 lock_.AssertAcquired(); 141 lock_.AssertAcquired();
137 } 142 }
138 143
139 std::unique_ptr<ConditionVariable> 144 std::unique_ptr<ConditionVariable>
140 SchedulerLockImpl::CreateConditionVariable() { 145 SchedulerLockImpl::CreateConditionVariable() {
141 return std::unique_ptr<ConditionVariable>(new ConditionVariable(&lock_)); 146 return std::unique_ptr<ConditionVariable>(new ConditionVariable(&lock_));
142 } 147 }
143 148
144 } // namespace internal 149 } // namespace internal
145 } // base 150 } // base
OLDNEW
« no previous file with comments | « base/task_scheduler/priority_queue_unittest.cc ('k') | base/task_scheduler/scheduler_lock_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698