| 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 |
| 11 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "base/memory/ptr_util.h" | 12 #include "base/memory/ptr_util.h" |
| 13 #include "base/task_scheduler/task_tracker.h" | 13 #include "base/task_scheduler/task_tracker.h" |
| 14 | 14 |
| 15 #if defined(OS_MACOSX) | 15 #if defined(OS_MACOSX) |
| 16 #include "base/mac/scoped_nsautorelease_pool.h" | 16 #include "base/mac/scoped_nsautorelease_pool.h" |
| 17 #elif defined(OS_WIN) | 17 #elif defined(OS_WIN) |
| 18 #include "base/win/com_init_check_hook.h" | |
| 19 #include "base/win/scoped_com_initializer.h" | 18 #include "base/win/scoped_com_initializer.h" |
| 20 #endif | 19 #endif |
| 21 | 20 |
| 22 namespace base { | 21 namespace base { |
| 23 namespace internal { | 22 namespace internal { |
| 24 | 23 |
| 25 class SchedulerWorker::Thread : public PlatformThread::Delegate { | 24 class SchedulerWorker::Thread : public PlatformThread::Delegate { |
| 26 public: | 25 public: |
| 27 ~Thread() override = default; | 26 ~Thread() override = default; |
| 28 | 27 |
| 29 static std::unique_ptr<Thread> Create(scoped_refptr<SchedulerWorker> outer) { | 28 static std::unique_ptr<Thread> Create(scoped_refptr<SchedulerWorker> outer) { |
| 30 std::unique_ptr<Thread> thread(new Thread(std::move(outer))); | 29 std::unique_ptr<Thread> thread(new Thread(std::move(outer))); |
| 31 thread->Initialize(); | 30 thread->Initialize(); |
| 32 if (thread->thread_handle_.is_null()) | 31 if (thread->thread_handle_.is_null()) |
| 33 return nullptr; | 32 return nullptr; |
| 34 return thread; | 33 return thread; |
| 35 } | 34 } |
| 36 | 35 |
| 37 // PlatformThread::Delegate. | 36 // PlatformThread::Delegate. |
| 38 void ThreadMain() override { | 37 void ThreadMain() override { |
| 39 // Set if this thread was detached. | 38 // Set if this thread was detached. |
| 40 std::unique_ptr<Thread> detached_thread; | 39 std::unique_ptr<Thread> detached_thread; |
| 41 | 40 |
| 42 outer_->delegate_->OnMainEntry(outer_.get()); | 41 outer_->delegate_->OnMainEntry(outer_.get()); |
| 43 | 42 |
| 44 // A SchedulerWorker starts out waiting for work. | 43 // A SchedulerWorker starts out waiting for work. |
| 45 outer_->delegate_->WaitForWork(&wake_up_event_); | 44 outer_->delegate_->WaitForWork(&wake_up_event_); |
| 46 | 45 |
| 47 // When defined(COM_INIT_CHECK_HOOK_ENABLED), ignore | 46 #if defined(OS_WIN) |
| 48 // SchedulerBackwardCompatibility::INIT_COM_STA to find incorrect uses of | |
| 49 // COM that should be running in a COM STA Task Runner. | |
| 50 #if defined(OS_WIN) && !defined(COM_INIT_CHECK_HOOK_ENABLED) | |
| 51 std::unique_ptr<win::ScopedCOMInitializer> com_initializer; | 47 std::unique_ptr<win::ScopedCOMInitializer> com_initializer; |
| 52 if (outer_->backward_compatibility_ == | 48 if (outer_->backward_compatibility_ == |
| 53 SchedulerBackwardCompatibility::INIT_COM_STA) { | 49 SchedulerBackwardCompatibility::INIT_COM_STA) { |
| 54 com_initializer = MakeUnique<win::ScopedCOMInitializer>(); | 50 com_initializer = MakeUnique<win::ScopedCOMInitializer>(); |
| 55 } | 51 } |
| 56 #endif | 52 #endif |
| 57 | 53 |
| 58 while (!outer_->ShouldExit()) { | 54 while (!outer_->ShouldExit()) { |
| 59 DCHECK(outer_); | 55 DCHECK(outer_); |
| 60 | 56 |
| (...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 332 // The ordering of the checks is important below. This SchedulerWorker may be | 328 // The ordering of the checks is important below. This SchedulerWorker may be |
| 333 // released and outlive |task_tracker_| in unit tests. However, when the | 329 // released and outlive |task_tracker_| in unit tests. However, when the |
| 334 // SchedulerWorker is released, |should_exit_| will be set, so check that | 330 // SchedulerWorker is released, |should_exit_| will be set, so check that |
| 335 // first. | 331 // first. |
| 336 return should_exit_.IsSet() || join_called_for_testing_.IsSet() || | 332 return should_exit_.IsSet() || join_called_for_testing_.IsSet() || |
| 337 task_tracker_->IsShutdownComplete(); | 333 task_tracker_->IsShutdownComplete(); |
| 338 } | 334 } |
| 339 | 335 |
| 340 } // namespace internal | 336 } // namespace internal |
| 341 } // namespace base | 337 } // namespace base |
| OLD | NEW |