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

Side by Side Diff: base/threading/thread.cc

Issue 2337253003: Add FlushForTesting to base::Thread. (Closed)
Patch Set: Created 4 years, 3 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 | « base/threading/thread.h ('k') | base/threading/thread_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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/threading/thread.h" 5 #include "base/threading/thread.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/bind_helpers.h" 8 #include "base/bind_helpers.h"
9 #include "base/lazy_instance.h" 9 #include "base/lazy_instance.h"
10 #include "base/location.h" 10 #include "base/location.h"
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
137 137
138 bool Thread::WaitUntilThreadStarted() const { 138 bool Thread::WaitUntilThreadStarted() const {
139 DCHECK(owning_sequence_checker_.CalledOnValidSequence()); 139 DCHECK(owning_sequence_checker_.CalledOnValidSequence());
140 if (!message_loop_) 140 if (!message_loop_)
141 return false; 141 return false;
142 base::ThreadRestrictions::ScopedAllowWait allow_wait; 142 base::ThreadRestrictions::ScopedAllowWait allow_wait;
143 start_event_.Wait(); 143 start_event_.Wait();
144 return true; 144 return true;
145 } 145 }
146 146
147 void Thread::FlushForTesting() {
danakj 2016/09/15 18:09:33 I'd prefer a free function in base/test/ actually.
gab 2016/09/15 20:18:33 Maybe discoverability is a reason? i.e. I just rea
148 DCHECK(owning_sequence_checker_.CalledOnValidSequence());
149 if (!message_loop_)
150 return;
151
152 WaitableEvent done(WaitableEvent::ResetPolicy::AUTOMATIC,
153 WaitableEvent::InitialState::NOT_SIGNALED);
154 task_runner()->PostTask(FROM_HERE,
155 Bind(&WaitableEvent::Signal, Unretained(&done)));
156 done.Wait();
157 }
158
147 void Thread::Stop() { 159 void Thread::Stop() {
148 DCHECK(joinable_); 160 DCHECK(joinable_);
149 161
150 // TODO(gab): Fix improper usage of this API (http://crbug.com/629139) and 162 // TODO(gab): Fix improper usage of this API (http://crbug.com/629139) and
151 // enable this check, until then synchronization with Start() via 163 // enable this check, until then synchronization with Start() via
152 // |thread_lock_| is required... 164 // |thread_lock_| is required...
153 // DCHECK(owning_sequence_checker_.CalledOnValidSequence()); 165 // DCHECK(owning_sequence_checker_.CalledOnValidSequence());
154 AutoLock lock(thread_lock_); 166 AutoLock lock(thread_lock_);
155 167
156 StopSoon(); 168 StopSoon();
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
331 run_loop_ = nullptr; 343 run_loop_ = nullptr;
332 } 344 }
333 345
334 void Thread::ThreadQuitHelper() { 346 void Thread::ThreadQuitHelper() {
335 DCHECK(run_loop_); 347 DCHECK(run_loop_);
336 run_loop_->QuitWhenIdle(); 348 run_loop_->QuitWhenIdle();
337 SetThreadWasQuitProperly(true); 349 SetThreadWasQuitProperly(true);
338 } 350 }
339 351
340 } // namespace base 352 } // namespace base
OLDNEW
« no previous file with comments | « base/threading/thread.h ('k') | base/threading/thread_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698