Taylor Cramer | 111eac0 | 2024-07-09 23:17:56 +0000 | [diff] [blame] | 1 | // 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 Cramer | 111eac0 | 2024-07-09 23:17:56 +0000 | [diff] [blame] | 17 | #include "pw_log/log.h" |
Wyatt Hepler | 14d4fd1 | 2024-07-10 17:10:42 +0000 | [diff] [blame] | 18 | #include "pw_system/system.h" |
Taylor Cramer | 111eac0 | 2024-07-09 23:17:56 +0000 | [diff] [blame] | 19 | |
Keir Mierle | 4d11a12 | 2024-07-25 17:50:02 +0000 | [diff] [blame] | 20 | namespace sense::system { |
Taylor Cramer | 111eac0 | 2024-07-09 23:17:56 +0000 | [diff] [blame] | 21 | namespace internal { |
| 22 | |
| 23 | /// A worker which delegates work to `pw::System`. |
Wyatt Hepler | 14d4fd1 | 2024-07-10 17:10:42 +0000 | [diff] [blame] | 24 | class SystemWorker final : public Worker { |
Taylor Cramer | 111eac0 | 2024-07-09 23:17:56 +0000 | [diff] [blame] | 25 | 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 Hepler | 14d4fd1 | 2024-07-10 17:10:42 +0000 | [diff] [blame] | 29 | } |
Taylor Cramer | 111eac0 | 2024-07-09 23:17:56 +0000 | [diff] [blame] | 30 | } |
| 31 | }; |
| 32 | |
| 33 | } // namespace internal |
| 34 | |
| 35 | Worker& GetWorker() { |
Wyatt Hepler | 14d4fd1 | 2024-07-10 17:10:42 +0000 | [diff] [blame] | 36 | static internal::SystemWorker worker; |
| 37 | return worker; |
Taylor Cramer | 111eac0 | 2024-07-09 23:17:56 +0000 | [diff] [blame] | 38 | } |
| 39 | |
Keir Mierle | 4d11a12 | 2024-07-25 17:50:02 +0000 | [diff] [blame] | 40 | } // namespace sense::system |