IceShard 1
A personal game engine project, with development focused on 2D/2.5D games.
Loading...
Searching...
No Matches
task_scheduler.hxx
Go to the documentation of this file.
1
3
4#pragma once
6#include <ice/task_queue.hxx>
7#include <ice/task_stage.hxx>
8
9namespace ice
10{
11
13 {
14 public:
15 inline explicit TaskScheduler(ice::TaskQueue& queue) noexcept;
16
17 inline auto schedule() noexcept;
18 inline auto schedule(ice::TaskFlags flags) noexcept;
19 inline auto schedule_delayed(ice::u32 delay_ms) noexcept;
20
21 inline auto operator co_await() noexcept;
22
23 private:
24 struct SchedulerAwaitable;
25
26 ice::TaskQueue& _queue;
27 };
28
30 {
34 ) noexcept
35 : _awaitable{ ._params = params }
36 , _queue{ queue }
37 { }
38
39 bool await_ready() const noexcept
40 {
41 return false;
42 }
43
44 auto await_suspend(ice::coroutine_handle<> coroutine) noexcept
45 {
46 _awaitable._coro = coroutine;
47 _queue.push_back(&_awaitable);
48 }
49
50 void await_resume() const noexcept
51 {
52 }
53
56 };
57
59 : _queue{ queue }
60 {
61 }
62
63 inline auto TaskScheduler::schedule() noexcept
64 {
65 struct Awaitable : SchedulerAwaitable
66 {
67 Awaitable(ice::TaskQueue& queue) noexcept
69 queue,
70 { .modifier = TaskAwaitableModifier::Unused }
71 }
72 { }
73 };
74
75 return Awaitable{ _queue };
76 }
77
78 inline auto TaskScheduler::schedule(ice::TaskFlags flags) noexcept
79 {
80 struct Awaitable : SchedulerAwaitable
81 {
82 Awaitable(
84 ice::TaskFlags flags
85 ) noexcept
87 queue,
88 {
90 .task_flags = flags
91 }
92 }
93 { }
94 };
95
96 return Awaitable{ _queue, flags };
97 }
98
99 inline auto TaskScheduler::schedule_delayed(ice::u32 delay_ms) noexcept
100 {
101 struct Awaitable : SchedulerAwaitable
102 {
103 Awaitable(
105 ice::u32 delay_ms
106 ) noexcept
108 queue,
109 {
111 .u32_value = delay_ms
112 }
113 }
114 { }
115 };
116
117 return Awaitable{ _queue, delay_ms };
118 }
119
120 inline auto TaskScheduler::operator co_await() noexcept
121 {
122 return schedule();
123 }
124
125} // namespace ice
Definition task_queue.hxx:13
TaskScheduler(ice::TaskQueue &queue) noexcept
Definition task_scheduler.hxx:58
auto schedule_delayed(ice::u32 delay_ms) noexcept
Definition task_scheduler.hxx:99
auto schedule() noexcept
Definition task_scheduler.hxx:63
Definition queue.hxx:111
SPDX-License-Identifier: MIT.
Definition array.hxx:12
@ DelayedExecution
Definition task_awaitable.hxx:15
@ Unused
Definition task_awaitable.hxx:13
@ PriorityFlags
Definition task_awaitable.hxx:14
std::coroutine_handle< Type > coroutine_handle
Definition task_types.hxx:42
std::uint32_t u32
Definition types.hxx:26
Definition task_awaitable.hxx:36
Definition task_awaitable.hxx:21
Definition task_flags.hxx:42
Definition task_scheduler.hxx:30
SchedulerAwaitable(ice::TaskQueue &queue, ice::TaskAwaitableParams params) noexcept
Definition task_scheduler.hxx:31
auto await_suspend(ice::coroutine_handle<> coroutine) noexcept
Definition task_scheduler.hxx:44
ice::TaskQueue & _queue
Definition task_scheduler.hxx:55
ice::TaskAwaitableBase _awaitable
Definition task_scheduler.hxx:54
void await_resume() const noexcept
Definition task_scheduler.hxx:50
bool await_ready() const noexcept
Definition task_scheduler.hxx:39