librf
event_v2.h
1 #pragma once
2 
3 namespace resumef
4 {
5 #ifndef DOXYGEN_SKIP_PROPERTY
6  namespace detail
7  {
8  struct event_v2_impl;
9  }
10 
11  inline namespace event_v2
12  {
13 #endif //DOXYGEN_SKIP_PROPERTY
14 
19  struct event_t
20  {
21  using event_impl_ptr = std::shared_ptr<detail::event_v2_impl>;
22  using clock_type = std::chrono::system_clock;
23 
28  event_t(bool initially = false);
29 
34  event_t(std::adopt_lock_t);
35 
39  ~event_t();
40 
45  void signal_all() const noexcept;
46 
53  void signal() const noexcept;
54 
59  void reset() const noexcept;
60 
61  struct [[nodiscard]] awaiter;
62 
68  awaiter operator co_await() const noexcept;
69 
78  awaiter wait() const noexcept;
79 
80  template<class _Btype>
81  struct timeout_awaitor_impl;
82 
83  struct [[nodiscard]] timeout_awaiter;
84 
94  template<class _Rep, class _Period>
95  timeout_awaiter wait_for(const std::chrono::duration<_Rep, _Period>& dt) const noexcept;
96 
106  template<class _Clock, class _Duration>
107  timeout_awaiter wait_until(const std::chrono::time_point<_Clock, _Duration>& tp) const noexcept;
108 
109 
110  template<class _Iter>
111  struct [[nodiscard]] any_awaiter;
112 
113  template<class _Iter
114 #ifndef DOXYGEN_SKIP_PROPERTY
115  COMMA_RESUMEF_ENABLE_IF(traits::is_iterator_of_v<_Iter, event_t>)
116 #endif //DOXYGEN_SKIP_PROPERTY
117  >
118 #ifndef DOXYGEN_SKIP_PROPERTY
119  RESUMEF_REQUIRES(_IteratorOfT<_Iter, event_t>)
120 #endif //DOXYGEN_SKIP_PROPERTY
121  static auto wait_any(_Iter begin_, _Iter end_)
122  ->any_awaiter<_Iter>;
123 
124  template<class _Cont
125 #ifndef DOXYGEN_SKIP_PROPERTY
126  COMMA_RESUMEF_ENABLE_IF(traits::is_container_of_v<_Cont, event_t>)
127 #endif //DOXYGEN_SKIP_PROPERTY
128  >
129 #ifndef DOXYGEN_SKIP_PROPERTY
130  RESUMEF_REQUIRES(_ContainerOfT<_Cont, event_t>)
131 #endif //DOXYGEN_SKIP_PROPERTY
132  static auto wait_any(const _Cont& cnt_)
133  ->any_awaiter<decltype(std::begin(cnt_))>;
134 
135  template<class _Iter>
136  struct [[nodiscard]] timeout_any_awaiter;
137 
138  template<class _Rep, class _Period, class _Iter
139 #ifndef DOXYGEN_SKIP_PROPERTY
140  COMMA_RESUMEF_ENABLE_IF(traits::is_iterator_of_v<_Iter, event_t>)
141 #endif //DOXYGEN_SKIP_PROPERTY
142  >
143 #ifndef DOXYGEN_SKIP_PROPERTY
144  RESUMEF_REQUIRES(_IteratorOfT<_Iter, event_t>)
145 #endif //DOXYGEN_SKIP_PROPERTY
146  static auto wait_any_for(const std::chrono::duration<_Rep, _Period>& dt, _Iter begin_, _Iter end_)
147  ->timeout_any_awaiter<_Iter>;
148 
149  template<class _Rep, class _Period, class _Cont
150 #ifndef DOXYGEN_SKIP_PROPERTY
151  COMMA_RESUMEF_ENABLE_IF(traits::is_container_of_v<_Cont, event_t>)
152 #endif //DOXYGEN_SKIP_PROPERTY
153  >
154 #ifndef DOXYGEN_SKIP_PROPERTY
155  RESUMEF_REQUIRES(_ContainerOfT<_Cont, event_t>)
156 #endif //DOXYGEN_SKIP_PROPERTY
157  static auto wait_any_for(const std::chrono::duration<_Rep, _Period>& dt, const _Cont& cnt_)
158  ->timeout_any_awaiter<decltype(std::begin(cnt_))>;
159 
160 
161 
162  template<class _Iter>
163  struct [[nodiscard]] all_awaiter;
164 
165  template<class _Iter
166 #ifndef DOXYGEN_SKIP_PROPERTY
167  COMMA_RESUMEF_ENABLE_IF(traits::is_iterator_of_v<_Iter, event_t>)
168 #endif //DOXYGEN_SKIP_PROPERTY
169  >
170 #ifndef DOXYGEN_SKIP_PROPERTY
171  RESUMEF_REQUIRES(_IteratorOfT<_Iter, event_t>)
172 #endif //DOXYGEN_SKIP_PROPERTY
173  static auto wait_all(_Iter begin_, _Iter end_)
174  ->all_awaiter<_Iter>;
175 
176  template<class _Cont
177 #ifndef DOXYGEN_SKIP_PROPERTY
178  COMMA_RESUMEF_ENABLE_IF(traits::is_container_of_v<_Cont, event_t>)
179 #endif //DOXYGEN_SKIP_PROPERTY
180  >
181 #ifndef DOXYGEN_SKIP_PROPERTY
182  RESUMEF_REQUIRES(_ContainerOfT<_Cont, event_t>)
183 #endif //DOXYGEN_SKIP_PROPERTY
184  static auto wait_all(const _Cont& cnt_)
185  ->all_awaiter<decltype(std::begin(cnt_))>;
186 
187 
188  template<class _Iter>
189  struct [[nodiscard]] timeout_all_awaiter;
190 
191  template<class _Rep, class _Period, class _Iter
192 #ifndef DOXYGEN_SKIP_PROPERTY
193  COMMA_RESUMEF_ENABLE_IF(traits::is_iterator_of_v<_Iter, event_t>)
194 #endif //DOXYGEN_SKIP_PROPERTY
195  >
196 #ifndef DOXYGEN_SKIP_PROPERTY
197  RESUMEF_REQUIRES(_IteratorOfT<_Iter, event_t>)
198 #endif //DOXYGEN_SKIP_PROPERTY
199  static auto wait_all_for(const std::chrono::duration<_Rep, _Period>& dt, _Iter begin_, _Iter end_)
200  ->timeout_all_awaiter<_Iter>;
201 
202  template<class _Rep, class _Period, class _Cont
203 #ifndef DOXYGEN_SKIP_PROPERTY
204  COMMA_RESUMEF_ENABLE_IF(traits::is_container_of_v<_Cont, event_t>)
205 #endif //DOXYGEN_SKIP_PROPERTY
206  >
207 #ifndef DOXYGEN_SKIP_PROPERTY
208  RESUMEF_REQUIRES(_ContainerOfT<_Cont, event_t>)
209 #endif //DOXYGEN_SKIP_PROPERTY
210  static auto wait_all_for(const std::chrono::duration<_Rep, _Period>& dt, const _Cont& cnt_)
211  ->timeout_all_awaiter<decltype(std::begin(cnt_))>;
212 
213  event_t(const event_t&) = default;
214  event_t(event_t&&) = default;
215  event_t& operator = (const event_t&) = default;
216  event_t& operator = (event_t&&) = default;
217  private:
218  event_impl_ptr _event;
219  };
220  }
221 }
resumef::event_t
用于协程的事件。
Definition: event_v2.h:19