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

Side by Side Diff: base/debug/activity_analyzer_unittest.cc

Issue 2422683002: Hold allocator lock while fetching 'used' count. (Closed)
Patch Set: Created 4 years, 2 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 | « no previous file | base/debug/activity_tracker_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/debug/activity_analyzer.h" 5 #include "base/debug/activity_analyzer.h"
6 6
7 #include <atomic> 7 #include <atomic>
8 #include <memory> 8 #include <memory>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
97 97
98 ~SimpleActivityThread() override {} 98 ~SimpleActivityThread() override {}
99 99
100 void Run() override { 100 void Run() override {
101 GlobalActivityTracker::Get() 101 GlobalActivityTracker::Get()
102 ->GetOrCreateTrackerForCurrentThread() 102 ->GetOrCreateTrackerForCurrentThread()
103 ->PushActivity(source_, activity_, data_); 103 ->PushActivity(source_, activity_, data_);
104 104
105 { 105 {
106 AutoLock auto_lock(lock_); 106 AutoLock auto_lock(lock_);
107 ready_.store(true, std::memory_order_relaxed); 107 ready_.store(true, std::memory_order_release);
108 while (!exit_.load(std::memory_order_relaxed)) 108 while (!exit_.load(std::memory_order_relaxed))
109 exit_condition_.Wait(); 109 exit_condition_.Wait();
110 } 110 }
111 111
112 GlobalActivityTracker::Get() 112 GlobalActivityTracker::Get()
113 ->GetOrCreateTrackerForCurrentThread() 113 ->GetOrCreateTrackerForCurrentThread()
114 ->PopActivity(); 114 ->PopActivity();
115 } 115 }
116 116
117 void Exit() { 117 void Exit() {
118 AutoLock auto_lock(lock_); 118 AutoLock auto_lock(lock_);
119 exit_.store(true, std::memory_order_relaxed); 119 exit_.store(true, std::memory_order_relaxed);
120 exit_condition_.Signal(); 120 exit_condition_.Signal();
121 } 121 }
122 122
123 void WaitReady() { 123 void WaitReady() {
124 SPIN_FOR_1_SECOND_OR_UNTIL_TRUE(ready_.load(std::memory_order_relaxed)); 124 SPIN_FOR_1_SECOND_OR_UNTIL_TRUE(ready_.load(std::memory_order_acquire));
125 } 125 }
126 126
127 private: 127 private:
128 const void* source_; 128 const void* source_;
129 Activity::Type activity_; 129 Activity::Type activity_;
130 ActivityData data_; 130 ActivityData data_;
131 131
132 std::atomic<bool> ready_; 132 std::atomic<bool> ready_;
133 std::atomic<bool> exit_; 133 std::atomic<bool> exit_;
134 Lock lock_; 134 Lock lock_;
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
172 ThreadActivityAnalyzer* ta2 = analyzer.GetFirstAnalyzer(); 172 ThreadActivityAnalyzer* ta2 = analyzer.GetFirstAnalyzer();
173 ASSERT_TRUE(ta2); 173 ASSERT_TRUE(ta2);
174 EXPECT_FALSE(analyzer.GetNextAnalyzer()); 174 EXPECT_FALSE(analyzer.GetNextAnalyzer());
175 ThreadActivityAnalyzer::ThreadKey tk2 = ta2->GetThreadKey(); 175 ThreadActivityAnalyzer::ThreadKey tk2 = ta2->GetThreadKey();
176 EXPECT_EQ(ta2, analyzer.GetAnalyzerForThread(tk2)); 176 EXPECT_EQ(ta2, analyzer.GetAnalyzerForThread(tk2));
177 EXPECT_EQ(tk1, tk2); 177 EXPECT_EQ(tk1, tk2);
178 } 178 }
179 179
180 } // namespace debug 180 } // namespace debug
181 } // namespace base 181 } // namespace base
OLDNEW
« no previous file with comments | « no previous file | base/debug/activity_tracker_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698