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

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

Issue 1100773004: base: Remove most uses of MessageLoopProxy (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 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
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/sequenced_worker_pool.h" 5 #include "base/threading/sequenced_worker_pool.h"
6 6
7 #include <list> 7 #include <list>
8 #include <map> 8 #include <map>
9 #include <set> 9 #include <set>
10 #include <utility> 10 #include <utility>
11 #include <vector> 11 #include <vector>
12 12
13 #include "base/atomic_sequence_num.h" 13 #include "base/atomic_sequence_num.h"
14 #include "base/callback.h" 14 #include "base/callback.h"
15 #include "base/compiler_specific.h" 15 #include "base/compiler_specific.h"
16 #include "base/critical_closure.h" 16 #include "base/critical_closure.h"
17 #include "base/lazy_instance.h" 17 #include "base/lazy_instance.h"
18 #include "base/logging.h" 18 #include "base/logging.h"
19 #include "base/memory/linked_ptr.h" 19 #include "base/memory/linked_ptr.h"
20 #include "base/message_loop/message_loop_proxy.h"
21 #include "base/stl_util.h" 20 #include "base/stl_util.h"
22 #include "base/strings/stringprintf.h" 21 #include "base/strings/stringprintf.h"
23 #include "base/synchronization/condition_variable.h" 22 #include "base/synchronization/condition_variable.h"
24 #include "base/synchronization/lock.h" 23 #include "base/synchronization/lock.h"
24 #include "base/thread_task_runner_handle.h"
25 #include "base/threading/platform_thread.h" 25 #include "base/threading/platform_thread.h"
26 #include "base/threading/simple_thread.h" 26 #include "base/threading/simple_thread.h"
27 #include "base/threading/thread_local.h" 27 #include "base/threading/thread_local.h"
28 #include "base/threading/thread_restrictions.h" 28 #include "base/threading/thread_restrictions.h"
29 #include "base/time/time.h" 29 #include "base/time/time.h"
30 #include "base/trace_event/trace_event.h" 30 #include "base/trace_event/trace_event.h"
31 #include "base/tracked_objects.h" 31 #include "base/tracked_objects.h"
32 32
33 #if defined(OS_MACOSX) 33 #if defined(OS_MACOSX)
34 #include "base/mac/scoped_nsautorelease_pool.h" 34 #include "base/mac/scoped_nsautorelease_pool.h"
(...skipping 1116 matching lines...) Expand 10 before | Expand all | Expand 10 after
1151 // Don't construct lazy instance on check. 1151 // Don't construct lazy instance on check.
1152 if (g_lazy_tls_ptr == NULL) 1152 if (g_lazy_tls_ptr == NULL)
1153 return SequenceToken(); 1153 return SequenceToken();
1154 1154
1155 SequencedWorkerPool::SequenceToken* token = g_lazy_tls_ptr.Get().Get(); 1155 SequencedWorkerPool::SequenceToken* token = g_lazy_tls_ptr.Get().Get();
1156 if (!token) 1156 if (!token)
1157 return SequenceToken(); 1157 return SequenceToken();
1158 return *token; 1158 return *token;
1159 } 1159 }
1160 1160
1161 SequencedWorkerPool::SequencedWorkerPool( 1161 // Note: the task runner is unset when SequencedWorkerPool is constructed
danakj 2015/04/21 20:16:31 Uhm.. I'm not sure what this comment means. Can yo
Sami 2015/04/23 17:48:25 Oh, sorry, accidentally left this in since I initi
1162 size_t max_threads, 1162 // between unit tests after MessageLoop destruction.
1163 const std::string& thread_name_prefix) 1163 SequencedWorkerPool::SequencedWorkerPool(size_t max_threads,
1164 : constructor_message_loop_(MessageLoopProxy::current()), 1164 const std::string& thread_name_prefix)
1165 : constructor_task_runner_(ThreadTaskRunnerHandle::Get()),
1165 inner_(new Inner(this, max_threads, thread_name_prefix, NULL)) { 1166 inner_(new Inner(this, max_threads, thread_name_prefix, NULL)) {
1166 } 1167 }
1167 1168
1168 SequencedWorkerPool::SequencedWorkerPool( 1169 SequencedWorkerPool::SequencedWorkerPool(size_t max_threads,
1169 size_t max_threads, 1170 const std::string& thread_name_prefix,
1170 const std::string& thread_name_prefix, 1171 TestingObserver* observer)
1171 TestingObserver* observer) 1172 : constructor_task_runner_(ThreadTaskRunnerHandle::Get()),
1172 : constructor_message_loop_(MessageLoopProxy::current()),
1173 inner_(new Inner(this, max_threads, thread_name_prefix, observer)) { 1173 inner_(new Inner(this, max_threads, thread_name_prefix, observer)) {
1174 } 1174 }
1175 1175
1176 SequencedWorkerPool::~SequencedWorkerPool() {} 1176 SequencedWorkerPool::~SequencedWorkerPool() {}
1177 1177
1178 void SequencedWorkerPool::OnDestruct() const { 1178 void SequencedWorkerPool::OnDestruct() const {
1179 DCHECK(constructor_message_loop_.get()); 1179 DCHECK(constructor_task_runner_.get());
danakj 2015/04/21 20:16:31 nit: no .get()
Sami 2015/04/23 17:48:25 Done.
1180 // Avoid deleting ourselves on a worker thread (which would 1180 // Avoid deleting ourselves on a worker thread (which would
1181 // deadlock). 1181 // deadlock).
1182 if (RunsTasksOnCurrentThread()) { 1182 if (RunsTasksOnCurrentThread()) {
1183 constructor_message_loop_->DeleteSoon(FROM_HERE, this); 1183 constructor_task_runner_->DeleteSoon(FROM_HERE, this);
1184 } else { 1184 } else {
1185 delete this; 1185 delete this;
1186 } 1186 }
1187 } 1187 }
1188 1188
1189 SequencedWorkerPool::SequenceToken SequencedWorkerPool::GetSequenceToken() { 1189 SequencedWorkerPool::SequenceToken SequencedWorkerPool::GetSequenceToken() {
1190 return inner_->GetSequenceToken(); 1190 return inner_->GetSequenceToken();
1191 } 1191 }
1192 1192
1193 SequencedWorkerPool::SequenceToken SequencedWorkerPool::GetNamedSequenceToken( 1193 SequencedWorkerPool::SequenceToken SequencedWorkerPool::GetNamedSequenceToken(
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
1293 1293
1294 void SequencedWorkerPool::FlushForTesting() { 1294 void SequencedWorkerPool::FlushForTesting() {
1295 inner_->CleanupForTesting(); 1295 inner_->CleanupForTesting();
1296 } 1296 }
1297 1297
1298 void SequencedWorkerPool::SignalHasWorkForTesting() { 1298 void SequencedWorkerPool::SignalHasWorkForTesting() {
1299 inner_->SignalHasWorkForTesting(); 1299 inner_->SignalHasWorkForTesting();
1300 } 1300 }
1301 1301
1302 void SequencedWorkerPool::Shutdown(int max_new_blocking_tasks_after_shutdown) { 1302 void SequencedWorkerPool::Shutdown(int max_new_blocking_tasks_after_shutdown) {
1303 DCHECK(constructor_message_loop_->BelongsToCurrentThread()); 1303 DCHECK(constructor_task_runner_->BelongsToCurrentThread());
1304 inner_->Shutdown(max_new_blocking_tasks_after_shutdown); 1304 inner_->Shutdown(max_new_blocking_tasks_after_shutdown);
1305 } 1305 }
1306 1306
1307 bool SequencedWorkerPool::IsShutdownInProgress() { 1307 bool SequencedWorkerPool::IsShutdownInProgress() {
1308 return inner_->IsShutdownInProgress(); 1308 return inner_->IsShutdownInProgress();
1309 } 1309 }
1310 1310
1311 } // namespace base 1311 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698