| 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 #ifndef BASE_TASK_SCHEDULER_TASK_TRACKER_POSIX_H_ | 5 #ifndef BASE_TASK_SCHEDULER_TASK_TRACKER_POSIX_H_ |
| 6 #define BASE_TASK_SCHEDULER_TASK_TRACKER_POSIX_H_ | 6 #define BASE_TASK_SCHEDULER_TASK_TRACKER_POSIX_H_ |
| 7 | 7 |
| 8 #include <memory> | 8 #include <memory> |
| 9 | 9 |
| 10 #include "base/base_export.h" | 10 #include "base/base_export.h" |
| 11 #include "base/logging.h" |
| 11 #include "base/macros.h" | 12 #include "base/macros.h" |
| 12 #include "base/task_scheduler/task_tracker.h" | 13 #include "base/task_scheduler/task_tracker.h" |
| 14 #include "base/threading/platform_thread.h" |
| 13 | 15 |
| 14 namespace base { | 16 namespace base { |
| 15 | 17 |
| 16 class MessageLoopForIO; | 18 class MessageLoopForIO; |
| 17 | 19 |
| 18 namespace internal { | 20 namespace internal { |
| 19 | 21 |
| 20 struct Task; | 22 struct Task; |
| 21 | 23 |
| 22 // A TaskTracker that instantiates a FileDescriptorWatcher in the scope in which | 24 // A TaskTracker that instantiates a FileDescriptorWatcher in the scope in which |
| 23 // a task runs. Used on all POSIX platforms except NaCl SFI. | 25 // a task runs. Used on all POSIX platforms except NaCl SFI. |
| 24 // set_watch_file_descriptor_message_loop() must be called before the | 26 // set_watch_file_descriptor_message_loop() must be called before the |
| 25 // TaskTracker can run tasks. | 27 // TaskTracker can run tasks. |
| 26 class BASE_EXPORT TaskTrackerPosix : public TaskTracker { | 28 class BASE_EXPORT TaskTrackerPosix : public TaskTracker { |
| 27 public: | 29 public: |
| 28 TaskTrackerPosix(); | 30 TaskTrackerPosix(); |
| 29 ~TaskTrackerPosix(); | 31 ~TaskTrackerPosix(); |
| 30 | 32 |
| 31 // Sets the MessageLoopForIO with which to setup FileDescriptorWatcher in the | 33 // Sets the MessageLoopForIO with which to setup FileDescriptorWatcher in the |
| 32 // scope in which tasks run. Must be called before starting to run tasks. | 34 // scope in which tasks run. Must be called before starting to run tasks. |
| 33 // External synchronization is required between a call to this and a call to | 35 // External synchronization is required between a call to this and a call to |
| 34 // RunTask(). | 36 // RunTask(). |
| 35 void set_watch_file_descriptor_message_loop( | 37 void set_watch_file_descriptor_message_loop( |
| 36 MessageLoopForIO* watch_file_descriptor_message_loop) { | 38 MessageLoopForIO* watch_file_descriptor_message_loop) { |
| 37 watch_file_descriptor_message_loop_ = watch_file_descriptor_message_loop; | 39 watch_file_descriptor_message_loop_ = watch_file_descriptor_message_loop; |
| 38 } | 40 } |
| 39 | 41 |
| 42 #if DCHECK_IS_ON() |
| 43 // TODO(robliao): http://crbug.com/698140. This addresses service thread tasks |
| 44 // that could run after the task scheduler has shut down. Anything from the |
| 45 // service thread is exempted from the task scheduler shutdown DCHECKs. |
| 46 void set_service_thread_handle( |
| 47 const PlatformThreadHandle& service_thread_handle) { |
| 48 DCHECK(!service_thread_handle.is_null()); |
| 49 service_thread_handle_ = service_thread_handle; |
| 50 } |
| 51 #endif |
| 52 |
| 40 private: | 53 private: |
| 41 // TaskTracker: | 54 // TaskTracker: |
| 42 void PerformRunTask(std::unique_ptr<Task> task) override; | 55 void PerformRunTask(std::unique_ptr<Task> task) override; |
| 43 | 56 |
| 57 #if DCHECK_IS_ON() |
| 58 bool IsExemptFromBlockingShutdownChecks() override; |
| 59 #endif |
| 60 |
| 44 MessageLoopForIO* watch_file_descriptor_message_loop_ = nullptr; | 61 MessageLoopForIO* watch_file_descriptor_message_loop_ = nullptr; |
| 45 | 62 |
| 63 #if DCHECK_IS_ON() |
| 64 PlatformThreadHandle service_thread_handle_; |
| 65 #endif |
| 66 |
| 46 DISALLOW_COPY_AND_ASSIGN(TaskTrackerPosix); | 67 DISALLOW_COPY_AND_ASSIGN(TaskTrackerPosix); |
| 47 }; | 68 }; |
| 48 | 69 |
| 49 } // namespace internal | 70 } // namespace internal |
| 50 } // namespace base | 71 } // namespace base |
| 51 | 72 |
| 52 #endif // BASE_TASK_SCHEDULER_TASK_TRACKER_POSIX_H_ | 73 #endif // BASE_TASK_SCHEDULER_TASK_TRACKER_POSIX_H_ |
| OLD | NEW |