fdoray | 9c72b03 | 2016-10-27 16:19:08 | [diff] [blame] | 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 |
| 3 | // found in the LICENSE file. |
| 4 | |
Gabriel Charette | 52fa3ae | 2019-04-15 21:44:37 | [diff] [blame] | 5 | #ifndef BASE_TASK_THREAD_POOL_TASK_TRACKER_POSIX_H_ |
| 6 | #define BASE_TASK_THREAD_POOL_TASK_TRACKER_POSIX_H_ |
fdoray | 9c72b03 | 2016-10-27 16:19:08 | [diff] [blame] | 7 | |
| 8 | #include <memory> |
| 9 | |
| 10 | #include "base/base_export.h" |
robliao | f10490bd | 2017-05-04 20:53:37 | [diff] [blame] | 11 | #include "base/logging.h" |
fdoray | 9c72b03 | 2016-10-27 16:19:08 | [diff] [blame] | 12 | #include "base/macros.h" |
Carlos Caballero | dd8bf7b04 | 2019-07-30 14:14:15 | [diff] [blame^] | 13 | #include "base/message_loop/message_pump_type.h" |
Gabriel Charette | 52fa3ae | 2019-04-15 21:44:37 | [diff] [blame] | 14 | #include "base/task/thread_pool/task_tracker.h" |
robliao | f10490bd | 2017-05-04 20:53:37 | [diff] [blame] | 15 | #include "base/threading/platform_thread.h" |
fdoray | 9c72b03 | 2016-10-27 16:19:08 | [diff] [blame] | 16 | |
| 17 | namespace base { |
fdoray | 9c72b03 | 2016-10-27 16:19:08 | [diff] [blame] | 18 | namespace internal { |
| 19 | |
| 20 | struct Task; |
| 21 | |
| 22 | // A TaskTracker that instantiates a FileDescriptorWatcher in the scope in which |
| 23 | // a task runs. Used on all POSIX platforms except NaCl SFI. |
Alexander Timin | 0439ffe | 2018-10-30 18:10:00 | [diff] [blame] | 24 | // set_io_thread_task_runner() must be called before the |
fdoray | 2cc05d1 | 2017-04-19 14:06:54 | [diff] [blame] | 25 | // TaskTracker can run tasks. |
fdoray | 9c72b03 | 2016-10-27 16:19:08 | [diff] [blame] | 26 | class BASE_EXPORT TaskTrackerPosix : public TaskTracker { |
| 27 | public: |
Francois Doray | 1519479 | 2018-04-05 17:01:09 | [diff] [blame] | 28 | TaskTrackerPosix(StringPiece name); |
Nico Weber | 564d350 | 2017-08-30 20:14:15 | [diff] [blame] | 29 | ~TaskTrackerPosix() override; |
fdoray | 9c72b03 | 2016-10-27 16:19:08 | [diff] [blame] | 30 | |
Alexander Timin | 0439ffe | 2018-10-30 18:10:00 | [diff] [blame] | 31 | // Sets the task runner with which to setup FileDescriptorWatcher in |
| 32 | // the scope in which tasks run. |io_thread_task_runner| must refer to |
Carlos Caballero | dd8bf7b04 | 2019-07-30 14:14:15 | [diff] [blame^] | 33 | // a Thread with MessagePumpType::IO. |
Alexander Timin | 0439ffe | 2018-10-30 18:10:00 | [diff] [blame] | 34 | // Must be called before starting to run tasks. |
fdoray | 2cc05d1 | 2017-04-19 14:06:54 | [diff] [blame] | 35 | // External synchronization is required between a call to this and a call to |
| 36 | // RunTask(). |
Alexander Timin | 0439ffe | 2018-10-30 18:10:00 | [diff] [blame] | 37 | void set_io_thread_task_runner( |
| 38 | scoped_refptr<SingleThreadTaskRunner> io_thread_task_runner) { |
| 39 | io_thread_task_runner_ = std::move(io_thread_task_runner); |
fdoray | 2cc05d1 | 2017-04-19 14:06:54 | [diff] [blame] | 40 | } |
| 41 | |
fdoray | b199f1be | 2017-05-29 23:00:03 | [diff] [blame] | 42 | protected: |
fdoray | 9c72b03 | 2016-10-27 16:19:08 | [diff] [blame] | 43 | // TaskTracker: |
Jesse McKenna | c331b12a7 | 2018-11-21 22:39:03 | [diff] [blame] | 44 | void RunOrSkipTask(Task task, |
Etienne Pierre-doray | ad3560c | 2019-04-24 18:14:13 | [diff] [blame] | 45 | TaskSource* task_source, |
Jesse McKenna | c331b12a7 | 2018-11-21 22:39:03 | [diff] [blame] | 46 | const TaskTraits& traits, |
| 47 | bool can_run_task) override; |
fdoray | 9c72b03 | 2016-10-27 16:19:08 | [diff] [blame] | 48 | |
fdoray | b199f1be | 2017-05-29 23:00:03 | [diff] [blame] | 49 | private: |
Alexander Timin | 0439ffe | 2018-10-30 18:10:00 | [diff] [blame] | 50 | scoped_refptr<SingleThreadTaskRunner> io_thread_task_runner_; |
fdoray | 9c72b03 | 2016-10-27 16:19:08 | [diff] [blame] | 51 | |
fdoray | 9c72b03 | 2016-10-27 16:19:08 | [diff] [blame] | 52 | DISALLOW_COPY_AND_ASSIGN(TaskTrackerPosix); |
| 53 | }; |
| 54 | |
| 55 | } // namespace internal |
| 56 | } // namespace base |
| 57 | |
Gabriel Charette | 52fa3ae | 2019-04-15 21:44:37 | [diff] [blame] | 58 | #endif // BASE_TASK_THREAD_POOL_TASK_TRACKER_POSIX_H_ |