Primiano Tucci | ce72002 | 2017-10-30 12:50:06 +0000 | [diff] [blame] | 1 | /* |
| 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 Tucci | d7d1be0 | 2017-10-30 17:41:34 +0000 | [diff] [blame^] | 17 | #ifndef PERFETTO_BASE_TASK_RUNNER_H_ |
| 18 | #define PERFETTO_BASE_TASK_RUNNER_H_ |
Primiano Tucci | ce72002 | 2017-10-30 12:50:06 +0000 | [diff] [blame] | 19 | |
| 20 | #include <functional> |
| 21 | |
| 22 | namespace perfetto { |
Primiano Tucci | d7d1be0 | 2017-10-30 17:41:34 +0000 | [diff] [blame^] | 23 | namespace base { |
Primiano Tucci | ce72002 | 2017-10-30 12:50:06 +0000 | [diff] [blame] | 24 | |
| 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 Tucci | ce72002 | 2017-10-30 12:50:06 +0000 | [diff] [blame] | 30 | |
| 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. |
| 35 | class 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 Tucci | d7d1be0 | 2017-10-30 17:41:34 +0000 | [diff] [blame^] | 44 | } // namespace base |
Primiano Tucci | ce72002 | 2017-10-30 12:50:06 +0000 | [diff] [blame] | 45 | } // namespace perfetto |
| 46 | |
Primiano Tucci | d7d1be0 | 2017-10-30 17:41:34 +0000 | [diff] [blame^] | 47 | #endif // PERFETTO_BASE_TASK_RUNNER_H_ |