| 54 | static void wtRebuildConfiguration(bool useCustom); |
| 55 | |
| 56 | static void workerThread_cb() |
| 57 | { |
| 58 | hex::log::debug("worker thread start"); |
| 59 | |
| 60 | /* Only call this with pendingTasksMutex taken. */ |
| 61 | auto stopWorkerThread = [] |
| 62 | { |
| 63 | workerThread.detach(); |
| 64 | workerThread = std::move(std::thread()); |
| 65 | pendingTasks.clear(); |
| 66 | hex::log::debug("worker thread shutdown"); |
| 67 | emergencyStop = busy = false; |
| 68 | }; |
| 69 | |
| 70 | for (;;) |
| 71 | { |
| 72 | std::function<void()> cb; |
| 73 | |
| 74 | { |
| 75 | const std::lock_guard<std::mutex> lock(pendingTasksMutex); |
| 76 | if (pendingTasks.empty()) |
| 77 | { |
| 78 | stopWorkerThread(); |
| 79 | return; |
| 80 | } |
| 81 | |
| 82 | cb = pendingTasks.front(); |
| 83 | pendingTasks.pop_front(); |
| 84 | } |
| 85 | |
| 86 | hex::log::debug("running worker function"); |
| 87 | |
| 88 | try |
| 89 | { |
| 90 | cb(); |
| 91 | } |
| 92 | catch (const std::exception& e) |
| 93 | { |
| 94 | const std::lock_guard<std::mutex> lock(pendingTasksMutex); |
| 95 | std::string message = e.what(); |
| 96 | hex::TaskManager::doLater( |
| 97 | [=] |
| 98 | { |
| 99 | hex::ui::ToastError::open( |
| 100 | fmt::format("FluxEngine error: {}", message)); |
| 101 | }); |
| 102 | stopWorkerThread(); |
| 103 | return; |
| 104 | } |
| 105 | catch (const EmergencyStopException& e) |
| 106 | { |
| 107 | const std::lock_guard<std::mutex> lock(pendingTasksMutex); |
| 108 | hex::log::debug("worker emergency stop"); |
| 109 | hex::TaskManager::doLater( |
| 110 | [=] |
| 111 | { |
| 112 | hex::ui::ToastError::open("FluxEngine operation cancelled"); |
| 113 | }); |