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

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

Issue 1128733002: Update from https://crrev.com/328418 (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 7 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 735 matching lines...) Expand 10 before | Expand all | Expand 10 after
770 SignalHasWork(); 770 SignalHasWork();
771 delete_these_outside_lock.clear(); 771 delete_these_outside_lock.clear();
772 772
773 // Complete thread creation outside the lock if necessary. 773 // Complete thread creation outside the lock if necessary.
774 if (new_thread_id) 774 if (new_thread_id)
775 FinishStartingAdditionalThread(new_thread_id); 775 FinishStartingAdditionalThread(new_thread_id);
776 776
777 this_worker->set_running_task_info( 777 this_worker->set_running_task_info(
778 SequenceToken(task.sequence_token_id), task.shutdown_behavior); 778 SequenceToken(task.sequence_token_id), task.shutdown_behavior);
779 779
780 tracked_objects::ThreadData::PrepareForStartOfRun(task.birth_tally);
781 tracked_objects::TaskStopwatch stopwatch; 780 tracked_objects::TaskStopwatch stopwatch;
782 stopwatch.Start(); 781 stopwatch.Start();
783 task.task.Run(); 782 task.task.Run();
784 stopwatch.Stop(); 783 stopwatch.Stop();
785 784
786 tracked_objects::ThreadData::TallyRunOnNamedThreadIfTracking( 785 tracked_objects::ThreadData::TallyRunOnNamedThreadIfTracking(
787 task, stopwatch); 786 task, stopwatch);
788 787
789 // Make sure our task is erased outside the lock for the 788 // Make sure our task is erased outside the lock for the
790 // same reason we do this with delete_these_oustide_lock. 789 // same reason we do this with delete_these_oustide_lock.
(...skipping 360 matching lines...) Expand 10 before | Expand all | Expand 10 after
1151 // Don't construct lazy instance on check. 1150 // Don't construct lazy instance on check.
1152 if (g_lazy_tls_ptr == NULL) 1151 if (g_lazy_tls_ptr == NULL)
1153 return SequenceToken(); 1152 return SequenceToken();
1154 1153
1155 SequencedWorkerPool::SequenceToken* token = g_lazy_tls_ptr.Get().Get(); 1154 SequencedWorkerPool::SequenceToken* token = g_lazy_tls_ptr.Get().Get();
1156 if (!token) 1155 if (!token)
1157 return SequenceToken(); 1156 return SequenceToken();
1158 return *token; 1157 return *token;
1159 } 1158 }
1160 1159
1161 SequencedWorkerPool::SequencedWorkerPool( 1160 SequencedWorkerPool::SequencedWorkerPool(size_t max_threads,
1162 size_t max_threads, 1161 const std::string& thread_name_prefix)
1163 const std::string& thread_name_prefix) 1162 : constructor_task_runner_(ThreadTaskRunnerHandle::Get()),
1164 : constructor_message_loop_(MessageLoopProxy::current()),
1165 inner_(new Inner(this, max_threads, thread_name_prefix, NULL)) { 1163 inner_(new Inner(this, max_threads, thread_name_prefix, NULL)) {
1166 } 1164 }
1167 1165
1168 SequencedWorkerPool::SequencedWorkerPool( 1166 SequencedWorkerPool::SequencedWorkerPool(size_t max_threads,
1169 size_t max_threads, 1167 const std::string& thread_name_prefix,
1170 const std::string& thread_name_prefix, 1168 TestingObserver* observer)
1171 TestingObserver* observer) 1169 : constructor_task_runner_(ThreadTaskRunnerHandle::Get()),
1172 : constructor_message_loop_(MessageLoopProxy::current()),
1173 inner_(new Inner(this, max_threads, thread_name_prefix, observer)) { 1170 inner_(new Inner(this, max_threads, thread_name_prefix, observer)) {
1174 } 1171 }
1175 1172
1176 SequencedWorkerPool::~SequencedWorkerPool() {} 1173 SequencedWorkerPool::~SequencedWorkerPool() {}
1177 1174
1178 void SequencedWorkerPool::OnDestruct() const { 1175 void SequencedWorkerPool::OnDestruct() const {
1179 DCHECK(constructor_message_loop_.get());
1180 // Avoid deleting ourselves on a worker thread (which would 1176 // Avoid deleting ourselves on a worker thread (which would
1181 // deadlock). 1177 // deadlock).
1182 if (RunsTasksOnCurrentThread()) { 1178 if (RunsTasksOnCurrentThread()) {
1183 constructor_message_loop_->DeleteSoon(FROM_HERE, this); 1179 constructor_task_runner_->DeleteSoon(FROM_HERE, this);
1184 } else { 1180 } else {
1185 delete this; 1181 delete this;
1186 } 1182 }
1187 } 1183 }
1188 1184
1189 SequencedWorkerPool::SequenceToken SequencedWorkerPool::GetSequenceToken() { 1185 SequencedWorkerPool::SequenceToken SequencedWorkerPool::GetSequenceToken() {
1190 return inner_->GetSequenceToken(); 1186 return inner_->GetSequenceToken();
1191 } 1187 }
1192 1188
1193 SequencedWorkerPool::SequenceToken SequencedWorkerPool::GetNamedSequenceToken( 1189 SequencedWorkerPool::SequenceToken SequencedWorkerPool::GetNamedSequenceToken(
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
1293 1289
1294 void SequencedWorkerPool::FlushForTesting() { 1290 void SequencedWorkerPool::FlushForTesting() {
1295 inner_->CleanupForTesting(); 1291 inner_->CleanupForTesting();
1296 } 1292 }
1297 1293
1298 void SequencedWorkerPool::SignalHasWorkForTesting() { 1294 void SequencedWorkerPool::SignalHasWorkForTesting() {
1299 inner_->SignalHasWorkForTesting(); 1295 inner_->SignalHasWorkForTesting();
1300 } 1296 }
1301 1297
1302 void SequencedWorkerPool::Shutdown(int max_new_blocking_tasks_after_shutdown) { 1298 void SequencedWorkerPool::Shutdown(int max_new_blocking_tasks_after_shutdown) {
1303 DCHECK(constructor_message_loop_->BelongsToCurrentThread()); 1299 DCHECK(constructor_task_runner_->BelongsToCurrentThread());
1304 inner_->Shutdown(max_new_blocking_tasks_after_shutdown); 1300 inner_->Shutdown(max_new_blocking_tasks_after_shutdown);
1305 } 1301 }
1306 1302
1307 bool SequencedWorkerPool::IsShutdownInProgress() { 1303 bool SequencedWorkerPool::IsShutdownInProgress() {
1308 return inner_->IsShutdownInProgress(); 1304 return inner_->IsShutdownInProgress();
1309 } 1305 }
1310 1306
1311 } // namespace base 1307 } // namespace base
OLDNEW
« no previous file with comments | « base/threading/sequenced_worker_pool.h ('k') | base/threading/sequenced_worker_pool_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698