aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTianjie Xu2017-06-07 19:59:55 -0500
committerTianjie Xu2017-06-08 14:10:30 -0500
commit379571098d1b597a2a5f159dfc7522cc4fde6c63 (patch)
treea7bbca448c95438c9832fb8067feecd8c4197508 /install.cpp
parent99e7216907e55ec6895e445190bb361fcfd437a7 (diff)
downloadplatform-bootable-recovery-379571098d1b597a2a5f159dfc7522cc4fde6c63.tar.gz
platform-bootable-recovery-379571098d1b597a2a5f159dfc7522cc4fde6c63.tar.xz
platform-bootable-recovery-379571098d1b597a2a5f159dfc7522cc4fde6c63.zip
Fix a race condition for temperature_logger
It's a rare deadlock that happens on fugu when the updater exits too fast due to a format error. Bug: 62379170 Test: fake-ota fails gracefully without hanging. Change-Id: Icbd6cff4f6b44ca20f4d75f8039332111f696cc5
Diffstat (limited to 'install.cpp')
-rw-r--r--install.cpp10
1 files changed, 7 insertions, 3 deletions
diff --git a/install.cpp b/install.cpp
index a1f2e4fb..db4ba937 100644
--- a/install.cpp
+++ b/install.cpp
@@ -27,6 +27,7 @@
27#include <unistd.h> 27#include <unistd.h>
28 28
29#include <algorithm> 29#include <algorithm>
30#include <atomic>
30#include <chrono> 31#include <chrono>
31#include <condition_variable> 32#include <condition_variable>
32#include <functional> 33#include <functional>
@@ -294,11 +295,12 @@ int update_binary_command(const std::string& package, ZipArchiveHandle zip,
294} 295}
295#endif // !AB_OTA_UPDATER 296#endif // !AB_OTA_UPDATER
296 297
297static void log_max_temperature(int* max_temperature) { 298static void log_max_temperature(int* max_temperature, const std::atomic<bool>& logger_finished) {
298 CHECK(max_temperature != nullptr); 299 CHECK(max_temperature != nullptr);
299 std::mutex mtx; 300 std::mutex mtx;
300 std::unique_lock<std::mutex> lck(mtx); 301 std::unique_lock<std::mutex> lck(mtx);
301 while (finish_log_temperature.wait_for(lck, 20s) == std::cv_status::timeout) { 302 while (!logger_finished.load() &&
303 finish_log_temperature.wait_for(lck, 20s) == std::cv_status::timeout) {
302 *max_temperature = std::max(*max_temperature, GetMaxValueFromThermalZone()); 304 *max_temperature = std::max(*max_temperature, GetMaxValueFromThermalZone());
303 } 305 }
304} 306}
@@ -403,7 +405,8 @@ static int try_update_binary(const std::string& package, ZipArchiveHandle zip, b
403 } 405 }
404 close(pipefd[1]); 406 close(pipefd[1]);
405 407
406 std::thread temperature_logger(log_max_temperature, max_temperature); 408 std::atomic<bool> logger_finished(false);
409 std::thread temperature_logger(log_max_temperature, max_temperature, std::ref(logger_finished));
407 410
408 *wipe_cache = false; 411 *wipe_cache = false;
409 bool retry_update = false; 412 bool retry_update = false;
@@ -467,6 +470,7 @@ static int try_update_binary(const std::string& package, ZipArchiveHandle zip, b
467 int status; 470 int status;
468 waitpid(pid, &status, 0); 471 waitpid(pid, &status, 0);
469 472
473 logger_finished.store(true);
470 finish_log_temperature.notify_one(); 474 finish_log_temperature.notify_one();
471 temperature_logger.join(); 475 temperature_logger.join();
472 476