xref: /aosp_15_r20/external/libchrome/base/single_thread_task_runner.h (revision 635a864187cb8b6c713ff48b7e790a6b21769273)
1*635a8641SAndroid Build Coastguard Worker // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2*635a8641SAndroid Build Coastguard Worker // Use of this source code is governed by a BSD-style license that can be
3*635a8641SAndroid Build Coastguard Worker // found in the LICENSE file.
4*635a8641SAndroid Build Coastguard Worker 
5*635a8641SAndroid Build Coastguard Worker #ifndef BASE_SINGLE_THREAD_TASK_RUNNER_H_
6*635a8641SAndroid Build Coastguard Worker #define BASE_SINGLE_THREAD_TASK_RUNNER_H_
7*635a8641SAndroid Build Coastguard Worker 
8*635a8641SAndroid Build Coastguard Worker #include "base/base_export.h"
9*635a8641SAndroid Build Coastguard Worker #include "base/sequenced_task_runner.h"
10*635a8641SAndroid Build Coastguard Worker 
11*635a8641SAndroid Build Coastguard Worker namespace base {
12*635a8641SAndroid Build Coastguard Worker 
13*635a8641SAndroid Build Coastguard Worker // A SingleThreadTaskRunner is a SequencedTaskRunner with one more
14*635a8641SAndroid Build Coastguard Worker // guarantee; namely, that all tasks are run on a single dedicated
15*635a8641SAndroid Build Coastguard Worker // thread.  Most use cases require only a SequencedTaskRunner, unless
16*635a8641SAndroid Build Coastguard Worker // there is a specific need to run tasks on only a single thread.
17*635a8641SAndroid Build Coastguard Worker //
18*635a8641SAndroid Build Coastguard Worker // SingleThreadTaskRunner implementations might:
19*635a8641SAndroid Build Coastguard Worker //   - Post tasks to an existing thread's MessageLoop (see
20*635a8641SAndroid Build Coastguard Worker //     MessageLoop::task_runner()).
21*635a8641SAndroid Build Coastguard Worker //   - Create their own worker thread and MessageLoop to post tasks to.
22*635a8641SAndroid Build Coastguard Worker //   - Add tasks to a FIFO and signal to a non-MessageLoop thread for them to
23*635a8641SAndroid Build Coastguard Worker //     be processed. This allows TaskRunner-oriented code run on threads
24*635a8641SAndroid Build Coastguard Worker //     running other kinds of message loop, e.g. Jingle threads.
25*635a8641SAndroid Build Coastguard Worker class BASE_EXPORT SingleThreadTaskRunner : public SequencedTaskRunner {
26*635a8641SAndroid Build Coastguard Worker  public:
27*635a8641SAndroid Build Coastguard Worker   // A more explicit alias to RunsTasksInCurrentSequence().
BelongsToCurrentThread()28*635a8641SAndroid Build Coastguard Worker   bool BelongsToCurrentThread() const { return RunsTasksInCurrentSequence(); }
29*635a8641SAndroid Build Coastguard Worker 
30*635a8641SAndroid Build Coastguard Worker  protected:
31*635a8641SAndroid Build Coastguard Worker   ~SingleThreadTaskRunner() override = default;
32*635a8641SAndroid Build Coastguard Worker };
33*635a8641SAndroid Build Coastguard Worker 
34*635a8641SAndroid Build Coastguard Worker }  // namespace base
35*635a8641SAndroid Build Coastguard Worker 
36*635a8641SAndroid Build Coastguard Worker #endif  // BASE_SINGLE_THREAD_TASK_RUNNER_H_
37