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 inline auto operator new(size_t size) noexcept -> void*
44 {
45 void* const ptr = TaskDebugAllocator::allocate(size);
47 return ptr;
48 }
49
50 inline void operator delete(void* ptr) noexcept
51 {
54 }
55#endif
56 };
57
58 template<typename Promise>
60 {
61 ice::coroutine_handle<> continuation = coro.promise().continuation();
62 if (continuation == nullptr)
63 {
64 continuation = std::noop_coroutine();
65 }
66 return continuation;
67 }
68
70 {
71 // Should never be executed
72 ICE_ASSERT_CORE(false);
73 }
74
75 inline auto TaskPromiseBase::initial_suspend() const noexcept
76 {
77 return ice::suspend_always{ };
78 }
79
80 inline auto TaskPromiseBase::final_suspend() const noexcept
81 {
82 return FinalAwaitable{ };
83 }
84
86 {
87 _continuation = coro;
88 }
89
90 inline auto TaskPromiseBase::continuation() const noexcept -> ice::coroutine_handle<>
91 {
92 return _continuation;
93 }
94
95 inline void TaskPromiseBase::unhandled_exception() const noexcept
96 {
97 ICE_ASSERT(false, "Unexpected exception in task promise! IceShard does not support exceptions!");
98 }
99
100} // namespace ice
#define ICE_ASSERT(condition, message,...)
Definition assert.hxx:29
#define ICE_ASSERT_CORE(expression)
Definition assert_core.hxx:43
SPDX-License-Identifier: MIT.
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:69
auto await_suspend(ice::coroutine_handle< Promise > coro) noexcept -> ice::coroutine_handle<>
Definition task_promise_base.hxx:59
constexpr bool await_ready() const noexcept
Definition task_promise_base.hxx:16
auto final_suspend() const noexcept
Definition task_promise_base.hxx:80
auto set_continuation(ice::coroutine_handle<> coro) noexcept
Definition task_promise_base.hxx:85
auto initial_suspend() const noexcept
Definition task_promise_base.hxx:75
ice::detail::TaskDebugAllocator TaskDebugAllocator
Definition task_promise_base.hxx:41
TaskPromiseBase() noexcept=default
void unhandled_exception() const noexcept
Definition task_promise_base.hxx:95
auto continuation() const noexcept -> ice::coroutine_handle<>
Definition task_promise_base.hxx:90
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