tin  1.5.9
policy.h
Go to the documentation of this file.
1 // Copyright (c) 2026 Tinverse LLC. All rights reserved.
2 // SPDX-License-Identifier: LicenseRef-Tinverse-Commercial
3 
9 
10 #pragma once
11 
12 #include <type_traits>
13 
14 #include "tsm/runtime/concepts.h"
15 
16 namespace tsm {
17 
24 namespace dispatch_model {
25 
26 struct direct
27 {};
28 struct queued
29 {};
31 {};
32 
33 } // namespace dispatch_model
34 
35 namespace overflow {
36 
38 {};
40 {};
42 {};
43 
44 } // namespace overflow
45 
46 template<typename Storage, typename Overflow>
52 {
53  static_assert(overflow_policy<Overflow>,
54  "tsm: queue policy requires a known overflow policy");
55 
56  using storage = Storage;
57  using overflow = Overflow;
58 };
59 
60 namespace detail {
61 
62 template<typename QueueOrStorage, typename Overflow>
63 struct select_runtime_queue_policy
64 {
66 };
67 
68 template<typename QueuePolicy, typename Overflow>
69 requires runtime::runtime_queue_policy<QueuePolicy>
70 struct select_runtime_queue_policy<QueuePolicy, Overflow>
71 {
72  using type = QueuePolicy;
73 };
74 
75 } // namespace detail
76 
77 template<typename DispatchModel,
78  typename QueueOrStorage,
79  typename Scheduler,
80  typename Overflow,
81  typename Transport>
89 {
90  private:
91  using selected_overflow =
92  std::conditional_t<overflow_policy<Scheduler>, Scheduler, Overflow>;
93  using selected_queue =
94  typename detail::select_runtime_queue_policy<QueueOrStorage,
95  selected_overflow>::type;
96 
97  public:
98  static_assert(dispatch_model_policy<DispatchModel>,
99  "tsm: runtime policy requires a known dispatch model");
100  static_assert(runtime::runtime_queue_policy<selected_queue>,
101  "tsm: runtime policy requires a known queue policy");
102 
103  using dispatch_model = DispatchModel;
104  using queue = selected_queue;
105 
106  using topology = DispatchModel;
107  using storage = typename selected_queue::storage;
108  using overflow = typename selected_queue::overflow;
109 };
110 
111 namespace runtime {
112 
113 template<typename Topology,
114  typename Storage,
115  typename Scheduler = void,
116  typename Overflow = ::tsm::overflow::reject_newest,
117  typename Transport = void>
118 using policy =
120 
121 } // namespace runtime
122 
123 } // namespace tsm
Concepts for runtime queues and dispatch policies.
requires(!has_transition_type_c< T > &&has_transition_member_c< T >) struct transitions_of< T >
Definition: transition.h:479
Definition: concepts.h:40
::tsm::overflow::reject_newest reject_newest
Definition: concepts.h:87
Definition: bare_metal.h:20
Definition: policy.h:27
Definition: policy.h:29
Definition: policy.h:40
Definition: policy.h:42
Definition: policy.h:38
Definition: policy.h:52
Storage storage
Definition: policy.h:56
Definition: policy.h:89
selected_queue queue
Definition: policy.h:104
DispatchModel topology
Definition: policy.h:106
DispatchModel dispatch_model
Definition: policy.h:103
typename selected_queue::storage storage
Definition: policy.h:107