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_async2/dispatcher_base.h" 17 #include "pw_sync/timed_thread_notification.h" 18 19 namespace pw::async2 { 20 21 // Implementor's note: 22 // 23 // This class defines the "basic" backend for the ``Dispatcher`` facade. 24 // 25 // All public and private methods here are necessary when implementing a 26 // ``Dispatcher`` backend. The private methods are invoked via the 27 // ``DispatcherImpl` via CRTP. 28 // 29 // The ``Dispatcher`` type here is publicly exposed as 30 // ``pw::async2::Dispatcher``. Any additional backend-specific public methods 31 // should include a ``Native`` prefix to indicate that they are 32 // platform-specific extensions and are not portable to other ``pw::async2`` 33 // backends. 34 class Dispatcher final : public DispatcherImpl<Dispatcher> { 35 public: 36 Dispatcher() = default; 37 Dispatcher(Dispatcher&) = delete; 38 Dispatcher(Dispatcher&&) = delete; 39 Dispatcher& operator=(Dispatcher&) = delete; 40 Dispatcher& operator=(Dispatcher&&) = delete; ~Dispatcher()41 ~Dispatcher() final { Deregister(); } 42 43 // NOTE: there are no public methods here because the public interface of 44 // ``Dispatcher`` is defined in ``DispatcherImpl``. 45 // 46 // Any additional public methods added here (or in another ``Dispatcher`` 47 // backend) would be backend-specific and should be clearly marked with a 48 // ``...Native`` suffix. 49 private: DoWake()50 void DoWake() final { notify_.release(); } 51 Poll<> DoRunUntilStalled(Task* task); 52 void DoRunToCompletion(Task* task); 53 friend class DispatcherImpl<Dispatcher>; 54 55 pw::sync::TimedThreadNotification notify_; 56 }; 57 58 } // namespace pw::async2 59