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

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

Issue 1852433005: Convert //base to use std::unique_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase after r384946 Created 4 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 <stdint.h> 7 #include <stdint.h>
8 8
9 #include <list> 9 #include <list>
10 #include <map> 10 #include <map>
11 #include <memory>
11 #include <set> 12 #include <set>
12 #include <utility> 13 #include <utility>
13 #include <vector> 14 #include <vector>
14 15
15 #include "base/atomic_sequence_num.h" 16 #include "base/atomic_sequence_num.h"
16 #include "base/callback.h" 17 #include "base/callback.h"
17 #include "base/compiler_specific.h" 18 #include "base/compiler_specific.h"
18 #include "base/critical_closure.h" 19 #include "base/critical_closure.h"
19 #include "base/lazy_instance.h" 20 #include "base/lazy_instance.h"
20 #include "base/logging.h" 21 #include "base/logging.h"
21 #include "base/macros.h" 22 #include "base/macros.h"
22 #include "base/memory/scoped_ptr.h" 23 #include "base/memory/ptr_util.h"
23 #include "base/stl_util.h" 24 #include "base/stl_util.h"
24 #include "base/strings/stringprintf.h" 25 #include "base/strings/stringprintf.h"
25 #include "base/synchronization/condition_variable.h" 26 #include "base/synchronization/condition_variable.h"
26 #include "base/synchronization/lock.h" 27 #include "base/synchronization/lock.h"
27 #include "base/thread_task_runner_handle.h" 28 #include "base/thread_task_runner_handle.h"
28 #include "base/threading/platform_thread.h" 29 #include "base/threading/platform_thread.h"
29 #include "base/threading/simple_thread.h" 30 #include "base/threading/simple_thread.h"
30 #include "base/threading/thread_local.h" 31 #include "base/threading/thread_local.h"
31 #include "base/threading/thread_restrictions.h" 32 #include "base/threading/thread_restrictions.h"
32 #include "base/time/time.h" 33 #include "base/time/time.h"
(...skipping 405 matching lines...) Expand 10 before | Expand all | Expand 10 after
438 const size_t max_threads_; 439 const size_t max_threads_;
439 440
440 const std::string thread_name_prefix_; 441 const std::string thread_name_prefix_;
441 442
442 // Associates all known sequence token names with their IDs. 443 // Associates all known sequence token names with their IDs.
443 std::map<std::string, int> named_sequence_tokens_; 444 std::map<std::string, int> named_sequence_tokens_;
444 445
445 // Owning pointers to all threads we've created so far, indexed by 446 // Owning pointers to all threads we've created so far, indexed by
446 // ID. Since we lazily create threads, this may be less than 447 // ID. Since we lazily create threads, this may be less than
447 // max_threads_ and will be initially empty. 448 // max_threads_ and will be initially empty.
448 using ThreadMap = std::map<PlatformThreadId, scoped_ptr<Worker>>; 449 using ThreadMap = std::map<PlatformThreadId, std::unique_ptr<Worker>>;
449 ThreadMap threads_; 450 ThreadMap threads_;
450 451
451 // Set to true when we're in the process of creating another thread. 452 // Set to true when we're in the process of creating another thread.
452 // See PrepareToStartAdditionalThreadIfHelpful for more. 453 // See PrepareToStartAdditionalThreadIfHelpful for more.
453 bool thread_being_created_; 454 bool thread_being_created_;
454 455
455 // Number of threads currently waiting for work. 456 // Number of threads currently waiting for work.
456 size_t waiting_thread_count_; 457 size_t waiting_thread_count_;
457 458
458 // Number of threads currently running tasks that have the BLOCK_SHUTDOWN 459 // Number of threads currently running tasks that have the BLOCK_SHUTDOWN
(...skipping 320 matching lines...) Expand 10 before | Expand all | Expand 10 after
779 AutoLock lock(lock_); 780 AutoLock lock(lock_);
780 return shutdown_called_; 781 return shutdown_called_;
781 } 782 }
782 783
783 void SequencedWorkerPool::Inner::ThreadLoop(Worker* this_worker) { 784 void SequencedWorkerPool::Inner::ThreadLoop(Worker* this_worker) {
784 { 785 {
785 AutoLock lock(lock_); 786 AutoLock lock(lock_);
786 DCHECK(thread_being_created_); 787 DCHECK(thread_being_created_);
787 thread_being_created_ = false; 788 thread_being_created_ = false;
788 auto result = threads_.insert( 789 auto result = threads_.insert(
789 std::make_pair(this_worker->tid(), make_scoped_ptr(this_worker))); 790 std::make_pair(this_worker->tid(), WrapUnique(this_worker)));
790 DCHECK(result.second); 791 DCHECK(result.second);
791 792
792 while (true) { 793 while (true) {
793 #if defined(OS_MACOSX) 794 #if defined(OS_MACOSX)
794 base::mac::ScopedNSAutoreleasePool autorelease_pool; 795 base::mac::ScopedNSAutoreleasePool autorelease_pool;
795 #endif 796 #endif
796 797
797 HandleCleanup(); 798 HandleCleanup();
798 799
799 // See GetWork for what delete_these_outside_lock is doing. 800 // See GetWork for what delete_these_outside_lock is doing.
(...skipping 595 matching lines...) Expand 10 before | Expand all | Expand 10 after
1395 void SequencedWorkerPool::Shutdown(int max_new_blocking_tasks_after_shutdown) { 1396 void SequencedWorkerPool::Shutdown(int max_new_blocking_tasks_after_shutdown) {
1396 DCHECK(constructor_task_runner_->BelongsToCurrentThread()); 1397 DCHECK(constructor_task_runner_->BelongsToCurrentThread());
1397 inner_->Shutdown(max_new_blocking_tasks_after_shutdown); 1398 inner_->Shutdown(max_new_blocking_tasks_after_shutdown);
1398 } 1399 }
1399 1400
1400 bool SequencedWorkerPool::IsShutdownInProgress() { 1401 bool SequencedWorkerPool::IsShutdownInProgress() {
1401 return inner_->IsShutdownInProgress(); 1402 return inner_->IsShutdownInProgress();
1402 } 1403 }
1403 1404
1404 } // namespace base 1405 } // 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