MCPcopy Create free account
hub / github.com/SakuraEngine/SakuraEngine / Task

Class Task

modules/core/task/src/task2.cpp:70–131  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

68 }
69
70 struct Task
71 {
72 skr::stl_function<void()> func;
73 std::coroutine_handle<skr_task_t::promise_type> coro;
74
75 Task() {}
76 Task(nullptr_t) {}
77
78 Task(skr::stl_function<void()>&& func)
79 : func(std::move(func))
80 {
81 }
82
83 Task(std::coroutine_handle<skr_task_t::promise_type>&& coro)
84 : coro(std::move(coro))
85 {
86 SKR_ASSERT(!this->coro.done());
87 coro = nullptr;
88 }
89
90 Task(Task&& other)
91 : func(std::move(other.func))
92 , coro(std::move(other.coro))
93 {
94 SKR_ASSERT(func || !this->coro.done());
95 other.coro = nullptr;
96 }
97
98 Task& operator=(Task&& other)
99 {
100 func = std::move(other.func);
101 coro = std::move(other.coro);
102 SKR_ASSERT(func || !this->coro.done());
103 other.coro = nullptr;
104 return *this;
105 }
106
107 void operator()()
108 {
109 SKR_ASSERT(*this);
110 if (func)
111 {
112 func();
113 func = {};
114 }
115 else
116 {
117#ifdef SKR_PROFILE_ENABLE
118 // the first fiber enter is in coroutine body
119 if(coro.promise().name != nullptr)
120 SkrFiberEnter(coro.promise().name);
121#endif
122 SKR_ASSERT(!coro.done());
123 coro.resume();
124 }
125 }
126
127 explicit operator bool() const

Callers 2

scheduleMethod · 0.85
scheduler_test.cppFile · 0.85

Calls 2

moveFunction · 0.50
doneMethod · 0.45

Tested by

no test coverage detected