blob: 5cfb1dad851f459fa97d463e2c44cd2a479a8022 [file] [log] [blame]
Primiano Tuccice720022017-10-30 12:50:06 +00001/*
2 * Copyright (C) 2017 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
Primiano Tuccid7d1be02017-10-30 17:41:34 +000017#ifndef PERFETTO_BASE_TASK_RUNNER_H_
18#define PERFETTO_BASE_TASK_RUNNER_H_
Primiano Tuccice720022017-10-30 12:50:06 +000019
20#include <functional>
21
22namespace perfetto {
Primiano Tuccid7d1be02017-10-30 17:41:34 +000023namespace base {
Primiano Tuccice720022017-10-30 12:50:06 +000024
25// A generic interface to allow the library clients to interleave the execution
26// of the tracing internals in their runtime environment.
27// The expectation is that all tasks, which are queued either via PostTask() or
28// AddFileDescriptorWatch(), are executed on the same sequence (either on the
29// same thread, or on a thread pool that gives sequencing guarantees).
Primiano Tuccice720022017-10-30 12:50:06 +000030
31// TODO(skyostil): rework this.
32// TODO: we should provide a reference implementation that just spins a
33// dedicated thread. For the moment the only implementation is in
34// test/test_task_runner.h.
35class TaskRunner {
36 public:
37 virtual ~TaskRunner() = default;
38
39 virtual void PostTask(std::function<void()>) = 0;
40 virtual void AddFileDescriptorWatch(int fd, std::function<void()>) = 0;
41 virtual void RemoveFileDescriptorWatch(int fd) = 0;
42};
43
Primiano Tuccid7d1be02017-10-30 17:41:34 +000044} // namespace base
Primiano Tuccice720022017-10-30 12:50:06 +000045} // namespace perfetto
46
Primiano Tuccid7d1be02017-10-30 17:41:34 +000047#endif // PERFETTO_BASE_TASK_RUNNER_H_