|
7 | 7 | #include <type_traits> |
8 | 8 | #include <utility> |
9 | 9 | #include <variant> |
10 | | -#include <memory> |
11 | 10 |
|
12 | 11 | #include "pot/memory/coro_memory.h" |
13 | 12 |
|
14 | | -namespace pot::coroutines |
15 | | -{ |
16 | | - template<typename T> |
17 | | - class task; |
18 | | - |
19 | | - template<typename T> |
20 | | - class lazy_task; |
21 | | -} |
22 | | - |
23 | | -namespace std |
24 | | -{ |
25 | | - |
26 | | -template <typename T, typename... Args> |
27 | | -struct coroutine_traits<pot::coroutines::lazy_task<T>, Args...> |
28 | | -{ |
29 | | - using promise_type = typename pot::coroutines::lazy_task<T>::promise_type; |
30 | | -}; |
31 | | -} // namespace std |
32 | | - |
33 | | -namespace pot::traits |
34 | | -{ |
35 | | -template <typename T> struct is_lazy_task : std::false_type |
36 | | -{ |
37 | | -}; |
38 | | -template <typename U> struct is_lazy_task<pot::coroutines::lazy_task<U>> : std::true_type |
39 | | -{ |
40 | | -}; |
41 | | -template <typename T> inline constexpr bool is_lazy_task_v = is_lazy_task<T>::value; |
42 | | - |
43 | | -template <typename T> struct awaitable_value |
44 | | -{ |
45 | | - using type = T; |
46 | | -}; |
47 | | -template <typename U> struct awaitable_value<coroutines::lazy_task<U>> |
48 | | -{ |
49 | | - using type = U; |
50 | | -}; |
51 | | -template <typename T> using awaitable_value_t = typename awaitable_value<T>::type; |
52 | | -template <typename T> struct is_task : std::false_type |
53 | | -{ |
54 | | -}; |
55 | | -template <typename U> struct is_task<pot::coroutines::task<U>> : std::true_type |
56 | | -{ |
57 | | -}; |
58 | | -template <typename T> inline constexpr bool is_task_v = is_task<T>::value; |
59 | | - |
60 | | -template <typename U> struct awaitable_value<coroutines::task<U>> |
61 | | -{ |
62 | | - using type = U; |
63 | | -}; |
64 | | -} // namespace pot::traits |
65 | | - |
66 | | - |
67 | | -namespace pot::coroutines |
68 | | -{ |
69 | | - struct task_meta |
70 | | - { |
71 | | - std::atomic<size_t> run_count{0}; |
72 | | - |
73 | | - // ~task_meta() { |
74 | | - // std::printf("Task finished with run_count = %zu\n", run_count.load()); |
75 | | - // } |
76 | | - }; |
77 | | -} |
78 | | - |
79 | 13 | namespace pot::coroutines::detail |
80 | 14 | { |
81 | | - |
82 | 15 | template <typename T> struct basic_promise_type |
83 | 16 | { |
84 | 17 | using value_type = T; |
@@ -172,7 +105,6 @@ template <typename T> struct basic_promise_type |
172 | 105 | std::atomic<bool> m_ready{false}; |
173 | 106 | std::atomic<void *> m_awaiter{nullptr}; |
174 | 107 | variant_type m_data{std::monostate{}}; |
175 | | - std::shared_ptr<pot::coroutines::task_meta> m_meta{std::make_shared<pot::coroutines::task_meta>()}; |
176 | 108 | }; |
177 | 109 | } // namespace pot::coroutines::detail |
178 | 110 |
|
@@ -291,17 +223,6 @@ template <typename T> class task |
291 | 223 | } |
292 | 224 | } |
293 | 225 |
|
294 | | - std::shared_ptr<pot::coroutines::task_meta> meta() const |
295 | | - { |
296 | | - if (m_handle) return m_handle.promise().m_meta; |
297 | | - return nullptr; |
298 | | - } |
299 | | - |
300 | | - void set_meta(std::shared_ptr<pot::coroutines::task_meta> meta) |
301 | | - { |
302 | | - if (m_handle) m_handle.promise().m_meta = std::move(meta); |
303 | | - } |
304 | | - |
305 | 226 | ~task() |
306 | 227 | { |
307 | 228 | if (m_handle) |
@@ -412,18 +333,6 @@ template <typename T> class lazy_task |
412 | 333 | } |
413 | 334 | } |
414 | 335 |
|
415 | | - std::shared_ptr<pot::coroutines::task_meta> meta() const |
416 | | - { |
417 | | - if (m_handle) return m_handle.promise().m_meta; |
418 | | - return nullptr; |
419 | | - } |
420 | | - |
421 | | - void set_meta(std::shared_ptr<pot::coroutines::task_meta> meta) |
422 | | - { |
423 | | - if (m_handle) m_handle.promise().m_meta = std::move(meta); |
424 | | - } |
425 | | - |
426 | | - |
427 | 336 | ~lazy_task() |
428 | 337 | { |
429 | 338 | if (m_handle) |
@@ -507,3 +416,46 @@ template <> struct lazy_task_promise_type_impl<void> final : detail::basic_promi |
507 | 416 | }; |
508 | 417 |
|
509 | 418 | } // namespace pot::coroutines |
| 419 | + |
| 420 | +namespace std |
| 421 | +{ |
| 422 | + |
| 423 | +template <typename T, typename... Args> |
| 424 | +struct coroutine_traits<pot::coroutines::lazy_task<T>, Args...> |
| 425 | +{ |
| 426 | + using promise_type = typename pot::coroutines::lazy_task<T>::promise_type; |
| 427 | +}; |
| 428 | +} // namespace std |
| 429 | + |
| 430 | +namespace pot::traits |
| 431 | +{ |
| 432 | +template <typename T> struct is_lazy_task : std::false_type |
| 433 | +{ |
| 434 | +}; |
| 435 | +template <typename U> struct is_lazy_task<pot::coroutines::lazy_task<U>> : std::true_type |
| 436 | +{ |
| 437 | +}; |
| 438 | +template <typename T> inline constexpr bool is_lazy_task_v = is_lazy_task<T>::value; |
| 439 | + |
| 440 | +template <typename T> struct awaitable_value |
| 441 | +{ |
| 442 | + using type = T; |
| 443 | +}; |
| 444 | +template <typename U> struct awaitable_value<coroutines::lazy_task<U>> |
| 445 | +{ |
| 446 | + using type = U; |
| 447 | +}; |
| 448 | +template <typename T> using awaitable_value_t = typename awaitable_value<T>::type; |
| 449 | +template <typename T> struct is_task : std::false_type |
| 450 | +{ |
| 451 | +}; |
| 452 | +template <typename U> struct is_task<pot::coroutines::task<U>> : std::true_type |
| 453 | +{ |
| 454 | +}; |
| 455 | +template <typename T> inline constexpr bool is_task_v = is_task<T>::value; |
| 456 | + |
| 457 | +template <typename U> struct awaitable_value<coroutines::task<U>> |
| 458 | +{ |
| 459 | + using type = U; |
| 460 | +}; |
| 461 | +} // namespace pot::traits |
0 commit comments