mirror of
https://github.com/WerWolv/ImHex.git
synced 2026-05-01 09:20:30 -05:00
sys: Improved startup time by running startup tasks in parallel
This commit is contained in:
@@ -43,15 +43,27 @@ namespace hex::init {
|
||||
return std::async(std::launch::async, [this] {
|
||||
bool status = true;
|
||||
|
||||
for (const auto &[name, task] : this->m_tasks) {
|
||||
{
|
||||
u32 tasksCompleted = 0;
|
||||
for (const auto &[name, task, async] : this->m_tasks) {
|
||||
if (!async) {
|
||||
std::lock_guard guard(this->m_progressMutex);
|
||||
this->m_currTaskName = name;
|
||||
}
|
||||
|
||||
try {
|
||||
auto runTask = [&, task = task] {
|
||||
if (!task())
|
||||
status = false;
|
||||
|
||||
tasksCompleted++;
|
||||
};
|
||||
|
||||
try {
|
||||
if (async) {
|
||||
std::thread(runTask).detach();
|
||||
} else {
|
||||
runTask();
|
||||
}
|
||||
|
||||
} catch (std::exception &e) {
|
||||
log::error("Init task '{}' threw an exception: {}", name, e.what());
|
||||
status = false;
|
||||
@@ -63,6 +75,9 @@ namespace hex::init {
|
||||
}
|
||||
}
|
||||
|
||||
while (tasksCompleted < this->m_tasks.size())
|
||||
std::this_thread::sleep_for(100ms);
|
||||
|
||||
// Small extra delay so the last progress step is visible
|
||||
std::this_thread::sleep_for(200ms);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user