| OLD | NEW |
| 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 |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 60 | 60 |
| 61 UpdateThreadPriority(GetDesiredThreadPriority()); | 61 UpdateThreadPriority(GetDesiredThreadPriority()); |
| 62 | 62 |
| 63 // Get the sequence containing the next task to execute. | 63 // Get the sequence containing the next task to execute. |
| 64 scoped_refptr<Sequence> sequence = | 64 scoped_refptr<Sequence> sequence = |
| 65 outer_->delegate_->GetWork(outer_.get()); | 65 outer_->delegate_->GetWork(outer_.get()); |
| 66 if (!sequence) { | 66 if (!sequence) { |
| 67 if (outer_->delegate_->CanDetach(outer_.get())) { | 67 if (outer_->delegate_->CanDetach(outer_.get())) { |
| 68 detached_thread = outer_->DetachThreadObject(DetachNotify::DELEGATE); | 68 detached_thread = outer_->DetachThreadObject(DetachNotify::DELEGATE); |
| 69 if (detached_thread) { | 69 if (detached_thread) { |
| 70 outer_ = nullptr; | |
| 71 DCHECK_EQ(detached_thread.get(), this); | 70 DCHECK_EQ(detached_thread.get(), this); |
| 72 PlatformThread::Detach(thread_handle_); | 71 PlatformThread::Detach(thread_handle_); |
| 73 break; | 72 break; |
| 74 } | 73 } |
| 75 } | 74 } |
| 76 WaitForWork(); | 75 WaitForWork(); |
| 77 continue; | 76 continue; |
| 78 } | 77 } |
| 79 | 78 |
| 80 if (outer_->task_tracker_->RunTask(sequence->TakeTask(), | 79 if (outer_->task_tracker_->RunTask(sequence->TakeTask(), |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 112 // We arrive here in the following cases: | 111 // We arrive here in the following cases: |
| 113 // Thread Detachment Request: | 112 // Thread Detachment Request: |
| 114 // * |detached_thread| will not be nullptr. | 113 // * |detached_thread| will not be nullptr. |
| 115 // ShouldExit() returns true: | 114 // ShouldExit() returns true: |
| 116 // * Shutdown: DetachThreadObject() returns the thread object. | 115 // * Shutdown: DetachThreadObject() returns the thread object. |
| 117 // * Cleanup: DetachThreadObject() returns the thread object. | 116 // * Cleanup: DetachThreadObject() returns the thread object. |
| 118 // * Join: DetachThreadObject() could return either the thread object or | 117 // * Join: DetachThreadObject() could return either the thread object or |
| 119 // nullptr. JoinForTesting() cleans up if we get nullptr. | 118 // nullptr. JoinForTesting() cleans up if we get nullptr. |
| 120 if (!detached_thread) | 119 if (!detached_thread) |
| 121 detached_thread = outer_->DetachThreadObject(DetachNotify::SILENT); | 120 detached_thread = outer_->DetachThreadObject(DetachNotify::SILENT); |
| 121 |
| 122 outer_->delegate_->OnMainExit(); |
| 122 } | 123 } |
| 123 | 124 |
| 124 void Join() { PlatformThread::Join(thread_handle_); } | 125 void Join() { PlatformThread::Join(thread_handle_); } |
| 125 | 126 |
| 126 void WakeUp() { wake_up_event_.Signal(); } | 127 void WakeUp() { wake_up_event_.Signal(); } |
| 127 | 128 |
| 128 bool IsWakeUpPending() { return wake_up_event_.IsSignaled(); } | 129 bool IsWakeUpPending() { return wake_up_event_.IsSignaled(); } |
| 129 | 130 |
| 130 private: | 131 private: |
| 131 Thread(scoped_refptr<SchedulerWorker> outer) | 132 Thread(scoped_refptr<SchedulerWorker> outer) |
| (...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 329 CreateThread(); | 330 CreateThread(); |
| 330 } | 331 } |
| 331 | 332 |
| 332 bool SchedulerWorker::ShouldExit() { | 333 bool SchedulerWorker::ShouldExit() { |
| 333 return task_tracker_->IsShutdownComplete() || | 334 return task_tracker_->IsShutdownComplete() || |
| 334 join_called_for_testing_.IsSet() || should_exit_.IsSet(); | 335 join_called_for_testing_.IsSet() || should_exit_.IsSet(); |
| 335 } | 336 } |
| 336 | 337 |
| 337 } // namespace internal | 338 } // namespace internal |
| 338 } // namespace base | 339 } // namespace base |
| OLD | NEW |