MCPcopy Create free account
hub / github.com/GDRETools/gdsdecomp / wait_for_completion

Method wait_for_completion

utility/task_manager.cpp:171–252  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

169}
170
171bool TaskManager::BaseTemplateTaskData::wait_for_completion(uint64_t timeout_s_no_progress) {
172 bool is_main_thread = Thread::is_main_thread();
173 _aborted = false;
174 if (is_canceled()) {
175 if (started && !runs_current_thread) {
176 _wait_after_cancel();
177 }
178 return true;
179 }
180 if (!started) {
181 if (auto_start) {
182 start();
183 } else {
184 while (!started && !is_canceled()) {
185 if (is_main_thread) {
186 if (TaskManager::get_singleton()->wait_until_next_frame()) {
187 break;
188 }
189 } else {
190 OS::get_singleton()->delay_usec(10000);
191 }
192 }
193 }
194 }
195 if (is_canceled()) {
196 if (started && !runs_current_thread) {
197 _wait_after_cancel();
198 }
199 return true;
200 }
201 if (runs_current_thread) {
202 run_on_current_thread();
203 } else {
204#if DEBUG_ENABLED
205 if (!is_main_thread) {
206 WARN_PRINT("Waiting for group task completion on non-main thread, progress will not be updated!");
207 }
208#endif
209 uint64_t last_progress_made = OS::get_singleton()->get_ticks_msec();
210 auto last_progress = get_current_task_step_value();
211 bool printed_warning = false;
212 [[maybe_unused]] uint64_t last_reported_mem_usage_ms = 0;
213 while (!is_done()) {
214#if 0
215 if (OS::get_singleton()->get_ticks_msec() - last_reported_mem_usage_ms > 1000) {
216 print_line("Memory usage: " + String::humanize_size(OS::get_singleton()->get_static_memory_usage()));
217 last_reported_mem_usage_ms = OS::get_singleton()->get_ticks_msec();
218 }
219#endif
220 if (timeout_s_no_progress != 0) {
221 auto curr_progress = get_current_task_step_value();
222 auto curr_time = OS::get_singleton()->get_ticks_msec();
223 if (curr_progress != last_progress) {
224 last_progress_made = curr_time;
225 last_progress = curr_progress;
226 } else {
227 auto delta = curr_time - last_progress_made;
228 if (!printed_warning && delta > (timeout_s_no_progress - 5) * 1000) {

Callers 2

Calls 1

wait_until_next_frameMethod · 0.80

Tested by

no test coverage detected