| 541 | } |
| 542 | |
| 543 | void TaskManager::DownloadQueueThread::main_loop() { |
| 544 | while (running) { |
| 545 | DownloadTaskID item; |
| 546 | if (!queue.try_pop(item)) { |
| 547 | // if (!waiting) { |
| 548 | // TaskManager::get_singleton()->update_progress_bg(); |
| 549 | // } |
| 550 | OS::get_singleton()->delay_usec(10000); |
| 551 | continue; |
| 552 | } |
| 553 | std::shared_ptr<DownloadTaskData> task; |
| 554 | tasks.if_contains(item, [&](auto &v) { |
| 555 | task = v.second; |
| 556 | if (task) { |
| 557 | MutexLock lock(worker_mutex); |
| 558 | running_task = task; |
| 559 | worker_cv.notify_all(); |
| 560 | } |
| 561 | }); |
| 562 | ERR_CONTINUE_MSG(!task, "Download task ID " + itos(item) + " not found"); |
| 563 | while (!task->is_done() && !task->is_waiting) { |
| 564 | task->update_progress(); |
| 565 | OS::get_singleton()->delay_usec(10000); |
| 566 | } |
| 567 | while (!task->is_done()) { |
| 568 | OS::get_singleton()->delay_usec(10000); |
| 569 | } |
| 570 | if (!task->is_waiting) { |
| 571 | task->finish_progress(); |
| 572 | } |
| 573 | if (task->is_canceled()) { |
| 574 | // pop off the rest of the queue |
| 575 | MutexLock lock(write_mutex); |
| 576 | tasks.for_each_m([&](auto &v) { |
| 577 | v.second->cancel(); |
| 578 | }); |
| 579 | tasks.clear(); |
| 580 | while (queue.try_pop(item)) { |
| 581 | } |
| 582 | } |
| 583 | } |
| 584 | } |
| 585 | |
| 586 | TaskManager::DownloadTaskID TaskManager::DownloadQueueThread::add_download_task(const String &p_download_url, const String &p_save_path, bool silent) { |
| 587 | MutexLock lock(write_mutex); |
no test coverage detected