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

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

Issue 2791243002: Rewrite base::Bind into base::BindOnce on trivial cases in base (Closed)
Patch Set: rebase Created 3 years, 8 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/sequenced_worker_pool_unittest.cc ('k') | base/threading/thread_perftest.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 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
149 } 149 }
150 150
151 void Thread::FlushForTesting() { 151 void Thread::FlushForTesting() {
152 DCHECK(owning_sequence_checker_.CalledOnValidSequence()); 152 DCHECK(owning_sequence_checker_.CalledOnValidSequence());
153 if (!message_loop_) 153 if (!message_loop_)
154 return; 154 return;
155 155
156 WaitableEvent done(WaitableEvent::ResetPolicy::AUTOMATIC, 156 WaitableEvent done(WaitableEvent::ResetPolicy::AUTOMATIC,
157 WaitableEvent::InitialState::NOT_SIGNALED); 157 WaitableEvent::InitialState::NOT_SIGNALED);
158 task_runner()->PostTask(FROM_HERE, 158 task_runner()->PostTask(FROM_HERE,
159 Bind(&WaitableEvent::Signal, Unretained(&done))); 159 BindOnce(&WaitableEvent::Signal, Unretained(&done)));
160 done.Wait(); 160 done.Wait();
161 } 161 }
162 162
163 void Thread::Stop() { 163 void Thread::Stop() {
164 DCHECK(joinable_); 164 DCHECK(joinable_);
165 165
166 // TODO(gab): Fix improper usage of this API (http://crbug.com/629139) and 166 // TODO(gab): Fix improper usage of this API (http://crbug.com/629139) and
167 // enable this check, until then synchronization with Start() via 167 // enable this check, until then synchronization with Start() via
168 // |thread_lock_| is required... 168 // |thread_lock_| is required...
169 // DCHECK(owning_sequence_checker_.CalledOnValidSequence()); 169 // DCHECK(owning_sequence_checker_.CalledOnValidSequence());
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
203 if (using_external_message_loop_) { 203 if (using_external_message_loop_) {
204 // Setting |stopping_| to true above should have been sufficient for this 204 // Setting |stopping_| to true above should have been sufficient for this
205 // thread to be considered "stopped" per it having never set its |running_| 205 // thread to be considered "stopped" per it having never set its |running_|
206 // bit by lack of its own ThreadMain. 206 // bit by lack of its own ThreadMain.
207 DCHECK(!IsRunning()); 207 DCHECK(!IsRunning());
208 message_loop_ = nullptr; 208 message_loop_ = nullptr;
209 return; 209 return;
210 } 210 }
211 211
212 task_runner()->PostTask( 212 task_runner()->PostTask(
213 FROM_HERE, base::Bind(&Thread::ThreadQuitHelper, Unretained(this))); 213 FROM_HERE, base::BindOnce(&Thread::ThreadQuitHelper, Unretained(this)));
214 } 214 }
215 215
216 void Thread::DetachFromSequence() { 216 void Thread::DetachFromSequence() {
217 DCHECK(owning_sequence_checker_.CalledOnValidSequence()); 217 DCHECK(owning_sequence_checker_.CalledOnValidSequence());
218 owning_sequence_checker_.DetachFromSequence(); 218 owning_sequence_checker_.DetachFromSequence();
219 } 219 }
220 220
221 PlatformThreadId Thread::GetThreadId() const { 221 PlatformThreadId Thread::GetThreadId() const {
222 // If the thread is created but not started yet, wait for |id_| being ready. 222 // If the thread is created but not started yet, wait for |id_| being ready.
223 base::ThreadRestrictions::ScopedAllowWait allow_wait; 223 base::ThreadRestrictions::ScopedAllowWait allow_wait;
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
357 run_loop_ = nullptr; 357 run_loop_ = nullptr;
358 } 358 }
359 359
360 void Thread::ThreadQuitHelper() { 360 void Thread::ThreadQuitHelper() {
361 DCHECK(run_loop_); 361 DCHECK(run_loop_);
362 run_loop_->QuitWhenIdle(); 362 run_loop_->QuitWhenIdle();
363 SetThreadWasQuitProperly(true); 363 SetThreadWasQuitProperly(true);
364 } 364 }
365 365
366 } // namespace base 366 } // namespace base
OLDNEW
« no previous file with comments | « base/threading/sequenced_worker_pool_unittest.cc ('k') | base/threading/thread_perftest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698