IceShard 1
A personal game engine project, with development focused on 2D/2.5D games.
Loading...
Searching...
No Matches
task_info.hxx
Go to the documentation of this file.
1
3
4#pragma once
5#include <ice/task_types.hxx>
6#include <atomic>
7
8namespace ice
9{
10
12 enum class TaskState : ice::u8
13 {
18
20 Created = 0x01,
21
23 Running = 0x02,
24
26 Suspended = 0x04,
27
29 Succeeded = 0x08,
30
32 Canceled = 0x10,
33
35 Failed = 0x20,
36
38 };
39
40 template<bool IsProfilerEnabled = false>
42
43 template<>
44 struct TaskProfilingInfo<true>
45 {
46 char const* fiber_name;
47 };
48
49 struct TaskInfo final
50 {
51 static constexpr bool HasProfilingInfo = false;
52
53 TaskInfo() noexcept = default;
54 TaskInfo(TaskInfo&&) noexcept = delete;
55 TaskInfo(TaskInfo const&) noexcept = delete;
56 auto operator=(TaskInfo&&) noexcept -> TaskInfo& = delete;
57 auto operator=(TaskInfo const&) noexcept -> TaskInfo& = delete;
58
59 auto aquire() noexcept -> ice::TaskInfo*;
60 void release() noexcept;
61
62 bool has_any(ice::TaskState state) const noexcept;
63
66
67 private:
68 std::atomic<ice::u8> _refcount = 1;
69 };
70
71 inline auto TaskInfo::aquire() noexcept -> TaskInfo*
72 {
73 ICE_ASSERT_CORE(_refcount.load(std::memory_order_relaxed) < 255);
74 _refcount.fetch_add(1, std::memory_order_relaxed);
75 return this;
76 }
77
78 inline void TaskInfo::release() noexcept
79 {
80 ICE_ASSERT_CORE(_refcount.load(std::memory_order_relaxed) != 0);
81 if (_refcount.fetch_sub(1, std::memory_order_relaxed) == 0)
82 {
83 delete this;
84 }
85 }
86
87 inline bool TaskInfo::has_any(ice::TaskState flags) const noexcept
88 {
89 return ice::has_any(state.load(std::memory_order_relaxed), flags);
90 }
91
92} // namespace ice
#define ICE_ASSERT_CORE(expression)
Definition assert_core.hxx:43
SPDX-License-Identifier: MIT.
Definition array.hxx:12
TaskState
All states a task can be in.
Definition task_info.hxx:13
@ Canceled
Task was canceled at any point of it's lifetime.
Definition task_info.hxx:32
@ Created
Task exists, but execution did not start.
Definition task_info.hxx:20
@ Running
Task, or one of it's subtasks are executing.
Definition task_info.hxx:23
@ Succeeded
Task finished execution with a valid result.
Definition task_info.hxx:29
@ Suspended
Task is suspended and awaits resuming. (Unused).
Definition task_info.hxx:26
@ Failed
Task finished execution but results are invalid.
Definition task_info.hxx:35
@ None
Definition log_severity.hxx:21
@ All
Definition log_severity.hxx:22
constexpr bool has_any(T value, T expected_flags) noexcept
Definition enum_flags.hxx:83
@ Invalid
Definition log_sink.hxx:22
std::uint8_t u8
Definition types.hxx:24
bool has_any(ice::TaskState state) const noexcept
Definition task_info.hxx:87
static constexpr bool HasProfilingInfo
Definition task_info.hxx:51
TaskInfo() noexcept=default
void release() noexcept
Definition task_info.hxx:78
std::atomic< ice::TaskState > state
Definition task_info.hxx:65
ice::TaskProfilingInfo< false > profiling
Definition task_info.hxx:64
auto aquire() noexcept -> ice::TaskInfo *
Definition task_info.hxx:71
char const * fiber_name
Definition task_info.hxx:46
Definition task_info.hxx:41