blob: 67a0f71b98a100986a1e6ca246b63f1c1ebcb4ce [file] [log] [blame]
fdoray9c72b032016-10-27 16:19:081// 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 Charette52fa3ae2019-04-15 21:44:375#ifndef BASE_TASK_THREAD_POOL_TASK_TRACKER_POSIX_H_
6#define BASE_TASK_THREAD_POOL_TASK_TRACKER_POSIX_H_
fdoray9c72b032016-10-27 16:19:087
8#include <memory>
9
10#include "base/base_export.h"
robliaof10490bd2017-05-04 20:53:3711#include "base/logging.h"
fdoray9c72b032016-10-27 16:19:0812#include "base/macros.h"
Carlos Caballerodd8bf7b042019-07-30 14:14:1513#include "base/message_loop/message_pump_type.h"
Gabriel Charette52fa3ae2019-04-15 21:44:3714#include "base/task/thread_pool/task_tracker.h"
robliaof10490bd2017-05-04 20:53:3715#include "base/threading/platform_thread.h"
fdoray9c72b032016-10-27 16:19:0816
17namespace base {
fdoray9c72b032016-10-27 16:19:0818namespace internal {
19
20struct 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 Timin0439ffe2018-10-30 18:10:0024// set_io_thread_task_runner() must be called before the
fdoray2cc05d12017-04-19 14:06:5425// TaskTracker can run tasks.
fdoray9c72b032016-10-27 16:19:0826class BASE_EXPORT TaskTrackerPosix : public TaskTracker {
27 public:
Francois Doray15194792018-04-05 17:01:0928 TaskTrackerPosix(StringPiece name);
Nico Weber564d3502017-08-30 20:14:1529 ~TaskTrackerPosix() override;
fdoray9c72b032016-10-27 16:19:0830
Alexander Timin0439ffe2018-10-30 18:10:0031 // 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 Caballerodd8bf7b042019-07-30 14:14:1533 // a Thread with MessagePumpType::IO.
Alexander Timin0439ffe2018-10-30 18:10:0034 // Must be called before starting to run tasks.
fdoray2cc05d12017-04-19 14:06:5435 // External synchronization is required between a call to this and a call to
36 // RunTask().
Alexander Timin0439ffe2018-10-30 18:10:0037 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);
fdoray2cc05d12017-04-19 14:06:5440 }
41
fdorayb199f1be2017-05-29 23:00:0342 protected:
fdoray9c72b032016-10-27 16:19:0843 // TaskTracker:
Jesse McKennac331b12a72018-11-21 22:39:0344 void RunOrSkipTask(Task task,
Etienne Pierre-dorayad3560c2019-04-24 18:14:1345 TaskSource* task_source,
Jesse McKennac331b12a72018-11-21 22:39:0346 const TaskTraits& traits,
47 bool can_run_task) override;
fdoray9c72b032016-10-27 16:19:0848
fdorayb199f1be2017-05-29 23:00:0349 private:
Alexander Timin0439ffe2018-10-30 18:10:0050 scoped_refptr<SingleThreadTaskRunner> io_thread_task_runner_;
fdoray9c72b032016-10-27 16:19:0851
fdoray9c72b032016-10-27 16:19:0852 DISALLOW_COPY_AND_ASSIGN(TaskTrackerPosix);
53};
54
55} // namespace internal
56} // namespace base
57
Gabriel Charette52fa3ae2019-04-15 21:44:3758#endif // BASE_TASK_THREAD_POOL_TASK_TRACKER_POSIX_H_