task_tracker_posix.h 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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. #ifndef BASE_TASK_THREAD_POOL_TASK_TRACKER_POSIX_H_
  5. #define BASE_TASK_THREAD_POOL_TASK_TRACKER_POSIX_H_
  6. #include <memory>
  7. #include "base/base_export.h"
  8. #include "base/macros.h"
  9. #include "base/message_loop/message_pump_type.h"
  10. #include "base/task/thread_pool/task_tracker.h"
  11. #include "base/threading/platform_thread.h"
  12. namespace base {
  13. namespace internal {
  14. struct Task;
  15. // A TaskTracker that instantiates a FileDescriptorWatcher in the scope in which
  16. // a task runs. Used on all POSIX platforms except NaCl SFI.
  17. // set_io_thread_task_runner() must be called before the
  18. // TaskTracker can run tasks.
  19. class BASE_EXPORT TaskTrackerPosix : public TaskTracker {
  20. public:
  21. TaskTrackerPosix(StringPiece name);
  22. ~TaskTrackerPosix() override;
  23. // Sets the task runner with which to setup FileDescriptorWatcher in
  24. // the scope in which tasks run. |io_thread_task_runner| must refer to
  25. // a Thread with MessagePumpType::IO.
  26. // Must be called before starting to run tasks.
  27. // External synchronization is required between a call to this and a call to
  28. // RunTask().
  29. void set_io_thread_task_runner(
  30. scoped_refptr<SingleThreadTaskRunner> io_thread_task_runner) {
  31. io_thread_task_runner_ = std::move(io_thread_task_runner);
  32. }
  33. protected:
  34. // TaskTracker:
  35. void RunTask(Task task,
  36. TaskSource* task_source,
  37. const TaskTraits& traits) override;
  38. private:
  39. scoped_refptr<SingleThreadTaskRunner> io_thread_task_runner_;
  40. DISALLOW_COPY_AND_ASSIGN(TaskTrackerPosix);
  41. };
  42. } // namespace internal
  43. } // namespace base
  44. #endif // BASE_TASK_THREAD_POOL_TASK_TRACKER_POSIX_H_