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

Side by Side Diff: base/task_scheduler/scheduler_worker.cc

Issue 2172123003: Add ScopedNSAutoreleasePool to SchedulerWorker's Main Loop (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase to 54b95be Created 4 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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/task_scheduler/scheduler_worker.h" 5 #include "base/task_scheduler/scheduler_worker.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <utility> 9 #include <utility>
10 10
11 #include "base/logging.h" 11 #include "base/logging.h"
12 #include "base/task_scheduler/task_tracker.h" 12 #include "base/task_scheduler/task_tracker.h"
13 #include "build/build_config.h" 13 #include "build/build_config.h"
14 14
15 #if defined(OS_MACOSX)
16 #include "base/mac/scoped_nsautorelease_pool.h"
17 #endif
18
15 namespace base { 19 namespace base {
16 namespace internal { 20 namespace internal {
17 21
18 class SchedulerWorker::Thread : public PlatformThread::Delegate { 22 class SchedulerWorker::Thread : public PlatformThread::Delegate {
19 public: 23 public:
20 ~Thread() override = default; 24 ~Thread() override = default;
21 25
22 static std::unique_ptr<Thread> Create(SchedulerWorker* outer) { 26 static std::unique_ptr<Thread> Create(SchedulerWorker* outer) {
23 std::unique_ptr<Thread> thread(new Thread(outer)); 27 std::unique_ptr<Thread> thread(new Thread(outer));
24 thread->Initialize(); 28 thread->Initialize();
25 if (thread->thread_handle_.is_null()) 29 if (thread->thread_handle_.is_null())
26 return nullptr; 30 return nullptr;
27 return thread; 31 return thread;
28 } 32 }
29 33
30 // PlatformThread::Delegate. 34 // PlatformThread::Delegate.
31 void ThreadMain() override { 35 void ThreadMain() override {
32 // Set if this thread was detached. 36 // Set if this thread was detached.
33 std::unique_ptr<Thread> detached_thread; 37 std::unique_ptr<Thread> detached_thread;
34 38
35 outer_->delegate_->OnMainEntry(outer_); 39 outer_->delegate_->OnMainEntry(outer_);
36 40
37 // A SchedulerWorker starts out waiting for work. 41 // A SchedulerWorker starts out waiting for work.
38 WaitForWork(); 42 WaitForWork();
39 43
40 while (!outer_->task_tracker_->IsShutdownComplete() && 44 while (!outer_->task_tracker_->IsShutdownComplete() &&
41 !outer_->ShouldExitForTesting()) { 45 !outer_->ShouldExitForTesting()) {
42 DCHECK(outer_); 46 DCHECK(outer_);
43 47
48 #if defined(OS_MACOSX)
49 mac::ScopedNSAutoreleasePool autorelease_pool;
50 #endif
51
44 #if !defined(OS_LINUX) 52 #if !defined(OS_LINUX)
45 UpdateThreadPriority(GetDesiredThreadPriority()); 53 UpdateThreadPriority(GetDesiredThreadPriority());
46 #endif 54 #endif
47 55
48 // Get the sequence containing the next task to execute. 56 // Get the sequence containing the next task to execute.
49 scoped_refptr<Sequence> sequence = outer_->delegate_->GetWork(outer_); 57 scoped_refptr<Sequence> sequence = outer_->delegate_->GetWork(outer_);
50 if (!sequence) { 58 if (!sequence) {
51 if (outer_->delegate_->CanDetach(outer_)) { 59 if (outer_->delegate_->CanDetach(outer_)) {
52 detached_thread = outer_->Detach(); 60 detached_thread = outer_->Detach();
53 if (detached_thread) { 61 if (detached_thread) {
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after
248 CreateThread(); 256 CreateThread();
249 } 257 }
250 258
251 bool SchedulerWorker::ShouldExitForTesting() const { 259 bool SchedulerWorker::ShouldExitForTesting() const {
252 AutoSchedulerLock auto_lock(should_exit_for_testing_lock_); 260 AutoSchedulerLock auto_lock(should_exit_for_testing_lock_);
253 return should_exit_for_testing_; 261 return should_exit_for_testing_;
254 } 262 }
255 263
256 } // namespace internal 264 } // namespace internal
257 } // namespace base 265 } // namespace base
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698