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

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

Issue 369703003: Reduce usage of MessageLoopProxy in base/ (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Explicit Created 6 years, 5 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 | Annotate | Revision Log
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/debug/trace_event.h" 17 #include "base/debug/trace_event.h"
18 #include "base/lazy_instance.h" 18 #include "base/lazy_instance.h"
19 #include "base/logging.h" 19 #include "base/logging.h"
20 #include "base/memory/linked_ptr.h" 20 #include "base/memory/linked_ptr.h"
21 #include "base/message_loop/message_loop_proxy.h" 21 #include "base/message_loop/message_loop_proxy.h"
22 #include "base/stl_util.h" 22 #include "base/stl_util.h"
23 #include "base/strings/stringprintf.h" 23 #include "base/strings/stringprintf.h"
24 #include "base/synchronization/condition_variable.h" 24 #include "base/synchronization/condition_variable.h"
25 #include "base/synchronization/lock.h" 25 #include "base/synchronization/lock.h"
26 #include "base/thread_task_runner_handle.h"
26 #include "base/threading/platform_thread.h" 27 #include "base/threading/platform_thread.h"
27 #include "base/threading/simple_thread.h" 28 #include "base/threading/simple_thread.h"
28 #include "base/threading/thread_local.h" 29 #include "base/threading/thread_local.h"
29 #include "base/threading/thread_restrictions.h" 30 #include "base/threading/thread_restrictions.h"
30 #include "base/time/time.h" 31 #include "base/time/time.h"
31 #include "base/tracked_objects.h" 32 #include "base/tracked_objects.h"
32 33
33 #if defined(OS_MACOSX) 34 #if defined(OS_MACOSX)
34 #include "base/mac/scoped_nsautorelease_pool.h" 35 #include "base/mac/scoped_nsautorelease_pool.h"
35 #elif defined(OS_WIN) 36 #elif defined(OS_WIN)
(...skipping 1098 matching lines...) Expand 10 before | Expand all | Expand 10 after
1134 // Don't construct lazy instance on check. 1135 // Don't construct lazy instance on check.
1135 if (g_lazy_tls_ptr == NULL) 1136 if (g_lazy_tls_ptr == NULL)
1136 return SequenceToken(); 1137 return SequenceToken();
1137 1138
1138 SequencedWorkerPool::SequenceToken* token = g_lazy_tls_ptr.Get().Get(); 1139 SequencedWorkerPool::SequenceToken* token = g_lazy_tls_ptr.Get().Get();
1139 if (!token) 1140 if (!token)
1140 return SequenceToken(); 1141 return SequenceToken();
1141 return *token; 1142 return *token;
1142 } 1143 }
1143 1144
1144 SequencedWorkerPool::SequencedWorkerPool( 1145 SequencedWorkerPool::SequencedWorkerPool(size_t max_threads,
1145 size_t max_threads, 1146 const std::string& thread_name_prefix)
1146 const std::string& thread_name_prefix) 1147 : constructor_task_runner_(ThreadTaskRunnerHandle::Get()),
1147 : constructor_message_loop_(MessageLoopProxy::current()),
1148 inner_(new Inner(this, max_threads, thread_name_prefix, NULL)) { 1148 inner_(new Inner(this, max_threads, thread_name_prefix, NULL)) {
1149 } 1149 }
1150 1150
1151 SequencedWorkerPool::SequencedWorkerPool( 1151 SequencedWorkerPool::SequencedWorkerPool(size_t max_threads,
1152 size_t max_threads, 1152 const std::string& thread_name_prefix,
1153 const std::string& thread_name_prefix, 1153 TestingObserver* observer)
1154 TestingObserver* observer) 1154 : constructor_task_runner_(ThreadTaskRunnerHandle::Get()),
1155 : constructor_message_loop_(MessageLoopProxy::current()),
1156 inner_(new Inner(this, max_threads, thread_name_prefix, observer)) { 1155 inner_(new Inner(this, max_threads, thread_name_prefix, observer)) {
1157 } 1156 }
1158 1157
1159 SequencedWorkerPool::~SequencedWorkerPool() {} 1158 SequencedWorkerPool::~SequencedWorkerPool() {}
1160 1159
1161 void SequencedWorkerPool::OnDestruct() const { 1160 void SequencedWorkerPool::OnDestruct() const {
1162 DCHECK(constructor_message_loop_.get()); 1161 DCHECK(constructor_task_runner_.get());
1163 // Avoid deleting ourselves on a worker thread (which would 1162 // Avoid deleting ourselves on a worker thread (which would
1164 // deadlock). 1163 // deadlock).
1165 if (RunsTasksOnCurrentThread()) { 1164 if (RunsTasksOnCurrentThread()) {
1166 constructor_message_loop_->DeleteSoon(FROM_HERE, this); 1165 constructor_task_runner_->DeleteSoon(FROM_HERE, this);
1167 } else { 1166 } else {
1168 delete this; 1167 delete this;
1169 } 1168 }
1170 } 1169 }
1171 1170
1172 SequencedWorkerPool::SequenceToken SequencedWorkerPool::GetSequenceToken() { 1171 SequencedWorkerPool::SequenceToken SequencedWorkerPool::GetSequenceToken() {
1173 return inner_->GetSequenceToken(); 1172 return inner_->GetSequenceToken();
1174 } 1173 }
1175 1174
1176 SequencedWorkerPool::SequenceToken SequencedWorkerPool::GetNamedSequenceToken( 1175 SequencedWorkerPool::SequenceToken SequencedWorkerPool::GetNamedSequenceToken(
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
1276 1275
1277 void SequencedWorkerPool::FlushForTesting() { 1276 void SequencedWorkerPool::FlushForTesting() {
1278 inner_->CleanupForTesting(); 1277 inner_->CleanupForTesting();
1279 } 1278 }
1280 1279
1281 void SequencedWorkerPool::SignalHasWorkForTesting() { 1280 void SequencedWorkerPool::SignalHasWorkForTesting() {
1282 inner_->SignalHasWorkForTesting(); 1281 inner_->SignalHasWorkForTesting();
1283 } 1282 }
1284 1283
1285 void SequencedWorkerPool::Shutdown(int max_new_blocking_tasks_after_shutdown) { 1284 void SequencedWorkerPool::Shutdown(int max_new_blocking_tasks_after_shutdown) {
1286 DCHECK(constructor_message_loop_->BelongsToCurrentThread()); 1285 DCHECK(constructor_task_runner_->RunsTasksOnCurrentThread());
1287 inner_->Shutdown(max_new_blocking_tasks_after_shutdown); 1286 inner_->Shutdown(max_new_blocking_tasks_after_shutdown);
1288 } 1287 }
1289 1288
1290 bool SequencedWorkerPool::IsShutdownInProgress() { 1289 bool SequencedWorkerPool::IsShutdownInProgress() {
1291 return inner_->IsShutdownInProgress(); 1290 return inner_->IsShutdownInProgress();
1292 } 1291 }
1293 1292
1294 } // namespace base 1293 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698