xref: /aosp_15_r20/external/pigweed/pw_async2_basic/public_overrides/pw_async2/dispatcher_native.h (revision 61c4878ac05f98d0ceed94b57d316916de578985)
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/thread_notification.h"
18 
19 namespace pw::async2::backend {
20 
21 // Windows GCC doesn't realize the nonvirtual destructor is protected and that
22 // the class is final.
23 PW_MODIFY_DIAGNOSTICS_PUSH();
24 PW_MODIFY_DIAGNOSTIC_GCC(ignored, "-Wnon-virtual-dtor");
25 
26 // Implementor's note:
27 //
28 // This class defines the "basic" backend for the ``Dispatcher`` facade.
29 //
30 // All public and private methods here are necessary when implementing a
31 // ``Dispatcher`` backend. The private methods are invoked via the
32 // ``DispatcherImpl` via CRTP.
33 //
34 // The ``Dispatcher`` type here is publicly exposed as
35 // ``pw::async2::Dispatcher``. Any additional backend-specific public methods
36 // should include a ``Native`` prefix to indicate that they are
37 // platform-specific extensions and are not portable to other ``pw::async2``
38 // backends.
39 class NativeDispatcher final : public NativeDispatcherBase {
40  public:
41   NativeDispatcher() = default;
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:
50   friend class ::pw::async2::Dispatcher;
51 
DoWake()52   void DoWake() final { notify_.release(); }
53   Poll<> DoRunUntilStalled(Dispatcher&, Task* task);
54   void DoRunToCompletion(Dispatcher&, Task* task);
55 
56   pw::sync::ThreadNotification notify_;
57 };
58 
59 PW_MODIFY_DIAGNOSTICS_POP();
60 
61 }  // namespace pw::async2::backend
62