Pigweed
Loading...
Searching...
No Matches
heap_dispatcher.h
1// Copyright 2023 The Pigweed Authors
2//
3// Licensed under the Apache License, Version 2.0 (the "License"); you may not
4// use this file except in compliance with the License. You may obtain a copy of
5// the License at
6//
7// https://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12// License for the specific language governing permissions and limitations under
13// the License.
14#pragma once
15
16#include "pw_async/function_dispatcher.h"
17
18namespace pw::async {
19
23class HeapDispatcher final : public FunctionDispatcher {
24 public:
25 HeapDispatcher(Dispatcher& dispatcher) : dispatcher_(dispatcher) {}
26 ~HeapDispatcher() override = default;
27
28 // FunctionDispatcher overrides:
29 Status PostAt(TaskFunction&& task_func,
30 chrono::SystemClock::time_point time) override;
31
32 // Dispatcher overrides:
33 inline void PostAt(Task& task,
34 chrono::SystemClock::time_point time) override {
35 return dispatcher_.PostAt(task, time);
36 }
37 inline bool Cancel(Task& task) override { return dispatcher_.Cancel(task); }
38
39 // VirtualSystemClock overrides:
40 inline chrono::SystemClock::time_point now() override {
41 return dispatcher_.now();
42 }
43
44 private:
45 Dispatcher& dispatcher_;
46};
47
48} // namespace pw::async
Definition: status.h:84
Definition: dispatcher.h:45
virtual bool Cancel(Task &task)=0
virtual void PostAt(Task &task, chrono::SystemClock::time_point time)=0
Definition: function_dispatcher.h:27
Definition: heap_dispatcher.h:23
Status PostAt(TaskFunction &&task_func, chrono::SystemClock::time_point time) override
Post dispatcher owned |task_func| function to be run at |time|.
chrono::SystemClock::time_point now() override
Returns the current time.
Definition: heap_dispatcher.h:40
bool Cancel(Task &task) override
Definition: heap_dispatcher.h:37
void PostAt(Task &task, chrono::SystemClock::time_point time) override
Definition: heap_dispatcher.h:33
Definition: task.h:31
virtual SystemClock::time_point now()=0
Returns the current time.