blob: 316ccb348a1a01f1b303d0de9ddca2c93f613926 [file] [log] [blame]
Taylor Cramer111eac02024-07-09 23:17:56 +00001// Copyright 2024 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
15#include "system/worker.h"
16
Taylor Cramer111eac02024-07-09 23:17:56 +000017#include "pw_log/log.h"
Wyatt Hepler14d4fd12024-07-10 17:10:42 +000018#include "pw_system/system.h"
Taylor Cramer111eac02024-07-09 23:17:56 +000019
Keir Mierle4d11a122024-07-25 17:50:02 +000020namespace sense::system {
Taylor Cramer111eac02024-07-09 23:17:56 +000021namespace internal {
22
23/// A worker which delegates work to `pw::System`.
Wyatt Hepler14d4fd12024-07-10 17:10:42 +000024class SystemWorker final : public Worker {
Taylor Cramer111eac02024-07-09 23:17:56 +000025 public:
26 void RunOnce(pw::Function<void()>&& work) override {
27 if (!pw::System().RunOnce(std::move(work))) {
28 PW_LOG_ERROR("Unable to schedule work on system worker.");
Wyatt Hepler14d4fd12024-07-10 17:10:42 +000029 }
Taylor Cramer111eac02024-07-09 23:17:56 +000030 }
31};
32
33} // namespace internal
34
35Worker& GetWorker() {
Wyatt Hepler14d4fd12024-07-10 17:10:42 +000036 static internal::SystemWorker worker;
37 return worker;
Taylor Cramer111eac02024-07-09 23:17:56 +000038}
39
Keir Mierle4d11a122024-07-25 17:50:02 +000040} // namespace sense::system