blob: c87e5f7ff1438c4599b18d5c146b2de89c9476ef [file] [log] [blame]
akalin@chromium.org062f9682012-02-15 10:43:19 +09001// 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
5#ifndef BASE_SINGLE_THREAD_TASK_RUNNER_H_
6#define BASE_SINGLE_THREAD_TASK_RUNNER_H_
7#pragma once
8
9#include "base/base_export.h"
10#include "base/sequenced_task_runner.h"
11
12namespace base {
13
14// A SingleThreadTaskRunner is a SequencedTaskRunner with one more
15// guarantee; namely, that all tasks are run on a single dedicated
16// thread. Most use cases require only a SequencedTaskRunner, unless
17// there is a specific need to run tasks on only a single dedicated.
18//
19// Some theoretical implementations of SingleThreadTaskRunner:
20//
21// - A SingleThreadTaskRunner that uses a single worker thread to
22// run posted tasks (i.e., a message loop).
23//
24// - A SingleThreadTaskRunner that stores the list of posted tasks
25// and has a method Run() that runs each runnable task in FIFO
26// order that must be run only from the thread the
27// SingleThreadTaskRunner was created on.
28class BASE_EXPORT SingleThreadTaskRunner : public SequencedTaskRunner {
rsleevi@chromium.orgd595b422012-04-06 12:14:30 +090029 public:
akalin@chromium.org062f9682012-02-15 10:43:19 +090030 // A more explicit alias to RunsTasksOnCurrentThread().
31 bool BelongsToCurrentThread() const {
32 return RunsTasksOnCurrentThread();
33 }
rsleevi@chromium.orgd595b422012-04-06 12:14:30 +090034
35 protected:
36 virtual ~SingleThreadTaskRunner() {}
akalin@chromium.org062f9682012-02-15 10:43:19 +090037};
38
39} // namespace base
40
41#endif // BASE_SERIAL_TASK_RUNNER_H_