IceShard 1
A personal game engine project, with development focused on 2D/2.5D games.
Loading...
Searching...
No Matches
task_promise_base.hxx
Go to the documentation of this file.
1
3
4#pragma once
5#include <ice/task_types.hxx>
7#include <ice/profiler.hxx>
8
9namespace ice
10{
11
13 {
15 {
16 constexpr bool await_ready() const noexcept { return false; }
17
18 template<typename Promise>
20
21 inline void await_resume() const noexcept;
22 };
23
24 inline auto initial_suspend() const noexcept;
25
26 inline auto final_suspend() const noexcept;
27
28 inline auto set_continuation(ice::coroutine_handle<> coro) noexcept;
29
30 inline auto continuation() const noexcept -> ice::coroutine_handle<>;
31
32 inline void unhandled_exception() const noexcept;
33 protected:
34 inline TaskPromiseBase() noexcept = default;
35
36 private:
37 ice::coroutine_handle<> _continuation;
38
39#if !ICE_RELEASE
40 public: // Override to track allocations of task objects
42
43 // TODO: We can actually do magic here!
44 // struct TaskShort { };
45 // auto operator new(size_t size, auto& self, TaskShort) noexcept -> void*
46 // {
47 // void* const ptr = TaskDebugAllocator::allocate(size);
48 // IPT_ALLOC_POOL(ptr, size, TaskDebugAllocator::pool());
49 // return ptr;
50 // }
51
52 inline auto operator new(size_t size) noexcept -> void*
53 {
54 void* const ptr = TaskDebugAllocator::allocate(size);
56 return ptr;
57 }
58
59 inline void operator delete(void* ptr) noexcept
60 {
63 }
64#endif
65 };
66
67 template<typename Promise>
69 {
70 ice::coroutine_handle<> continuation = coro.promise().continuation();
71 if (continuation == nullptr)
72 {
73 continuation = std::noop_coroutine();
74 }
75 return continuation;
76 }
77
79 {
80 // Should never be executed
81 ICE_ASSERT_CORE(false);
82 }
83
84 inline auto TaskPromiseBase::initial_suspend() const noexcept
85 {
86 return ice::suspend_always{ };
87 }
88
89 inline auto TaskPromiseBase::final_suspend() const noexcept
90 {
91 return FinalAwaitable{ };
92 }
93
95 {
96 _continuation = coro;
97 }
98
99 inline auto TaskPromiseBase::continuation() const noexcept -> ice::coroutine_handle<>
100 {
101 return _continuation;
102 }
103
104 inline void TaskPromiseBase::unhandled_exception() const noexcept
105 {
106 ICE_ASSERT(false, "Unexpected exception in task promise! IceShard does not support exceptions!");
107 }
108
109} // namespace ice
#define ICE_ASSERT(condition, message,...)
Definition assert.hxx:29
#define ICE_ASSERT_CORE(expression)
Definition assert_core.hxx:43
Root namespace for all APIs part of the IceShard engine project.
Definition array.hxx:12
std::coroutine_handle< Type > coroutine_handle
Definition task_types.hxx:42
std::suspend_always suspend_always
Definition task_types.hxx:43
#define IPT_ALLOC_POOL(ptr, size, name)
Definition profiler.hxx:66
#define IPT_DEALLOC_POOL(ptr, name)
Definition profiler.hxx:67
Definition task_promise_base.hxx:15
void await_resume() const noexcept
Definition task_promise_base.hxx:78
auto await_suspend(ice::coroutine_handle< Promise > coro) noexcept -> ice::coroutine_handle<>
Definition task_promise_base.hxx:68
constexpr bool await_ready() const noexcept
Definition task_promise_base.hxx:16
auto final_suspend() const noexcept
Definition task_promise_base.hxx:89
auto set_continuation(ice::coroutine_handle<> coro) noexcept
Definition task_promise_base.hxx:94
auto initial_suspend() const noexcept
Definition task_promise_base.hxx:84
ice::detail::TaskDebugAllocator TaskDebugAllocator
Definition task_promise_base.hxx:41
TaskPromiseBase() noexcept=default
void unhandled_exception() const noexcept
Definition task_promise_base.hxx:104
auto continuation() const noexcept -> ice::coroutine_handle<>
Definition task_promise_base.hxx:99
Definition task_debug_allocator.hxx:23
static auto allocate(size_t size) noexcept -> void *
Definition task_debug_allocator.hxx:35
static void deallocate(void *pointer) noexcept
Definition task_debug_allocator.hxx:40
static auto pool() noexcept -> ice::String
Definition task_debug_allocator.hxx:24