single_thread_task_runner.h 1.4 KB

123456789101112131415161718192021222324252627282930313233343536
  1. // Copyright (c) 2012 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_SINGLE_THREAD_TASK_RUNNER_H_
  5. #define BASE_SINGLE_THREAD_TASK_RUNNER_H_
  6. #include "base/base_export.h"
  7. #include "base/sequenced_task_runner.h"
  8. namespace base {
  9. // A SingleThreadTaskRunner is a SequencedTaskRunner with one more
  10. // guarantee; namely, that all tasks are run on a single dedicated
  11. // thread. Most use cases require only a SequencedTaskRunner, unless
  12. // there is a specific need to run tasks on only a single thread.
  13. //
  14. // SingleThreadTaskRunner implementations might:
  15. // - Post tasks to an existing thread's MessageLoop (see
  16. // MessageLoop::task_runner()).
  17. // - Create their own worker thread and MessageLoop to post tasks to.
  18. // - Add tasks to a FIFO and signal to a non-MessageLoop thread for them to
  19. // be processed. This allows TaskRunner-oriented code run on threads
  20. // running other kinds of message loop, e.g. Jingle threads.
  21. class BASE_EXPORT SingleThreadTaskRunner : public SequencedTaskRunner {
  22. public:
  23. // A more explicit alias to RunsTasksInCurrentSequence().
  24. bool BelongsToCurrentThread() const { return RunsTasksInCurrentSequence(); }
  25. protected:
  26. ~SingleThreadTaskRunner() override = default;
  27. };
  28. } // namespace base
  29. #endif // BASE_SINGLE_THREAD_TASK_RUNNER_H_