mirror of
https://github.com/78/xiaozhi-esp32.git
synced 2026-07-21 10:15:56 +00:00
Remove std::thread wrappers in display callbacks to fix thread safety
Remove detached threads that were calling SetChatMessage from download/upgrade progress callbacks. The DisplayLockGuard mutex already provides thread safety, so we can call display methods directly from the callback thread without spawning additional threads, which were causing race conditions. Co-authored-by: 78 <4488133+78@users.noreply.github.com>
This commit is contained in:
co-authored by
78
parent
104726903f
commit
62c060da45
+6
-10
@@ -369,11 +369,9 @@ void Application::CheckAssetsVersion() {
|
||||
display->SetChatMessage("system", Lang::Strings::PLEASE_WAIT);
|
||||
|
||||
bool success = assets.Download(download_url, [display](int progress, size_t speed) -> void {
|
||||
std::thread([display, progress, speed]() {
|
||||
char buffer[32];
|
||||
snprintf(buffer, sizeof(buffer), "%d%% %uKB/s", progress, speed / 1024);
|
||||
display->SetChatMessage("system", buffer);
|
||||
}).detach();
|
||||
char buffer[32];
|
||||
snprintf(buffer, sizeof(buffer), "%d%% %uKB/s", progress, speed / 1024);
|
||||
display->SetChatMessage("system", buffer);
|
||||
});
|
||||
|
||||
board.SetPowerSaveLevel(PowerSaveLevel::LOW_POWER);
|
||||
@@ -922,11 +920,9 @@ bool Application::UpgradeFirmware(const std::string& url, const std::string& ver
|
||||
vTaskDelay(pdMS_TO_TICKS(1000));
|
||||
|
||||
bool upgrade_success = Ota::Upgrade(upgrade_url, [display](int progress, size_t speed) {
|
||||
std::thread([display, progress, speed]() {
|
||||
char buffer[32];
|
||||
snprintf(buffer, sizeof(buffer), "%d%% %uKB/s", progress, speed / 1024);
|
||||
display->SetChatMessage("system", buffer);
|
||||
}).detach();
|
||||
char buffer[32];
|
||||
snprintf(buffer, sizeof(buffer), "%d%% %uKB/s", progress, speed / 1024);
|
||||
display->SetChatMessage("system", buffer);
|
||||
});
|
||||
|
||||
if (!upgrade_success) {
|
||||
|
||||
Reference in New Issue
Block a user