Avoid frequently wait if log tag prop not found (#1580)

This commit is contained in:
LoveSy 2022-01-29 18:24:37 +08:00 committed by GitHub
parent 223fdb5c10
commit 5fd296e3ad
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 6 additions and 2 deletions

View File

@ -249,7 +249,7 @@ void Logcat::EnsureLogWatchDog() {
constexpr static auto kLogdMainSizeProp = "persist.logd.size.main"sv; constexpr static auto kLogdMainSizeProp = "persist.logd.size.main"sv;
constexpr static auto kLogdCrashSizeProp = "persist.logd.size.crash"sv; constexpr static auto kLogdCrashSizeProp = "persist.logd.size.crash"sv;
constexpr static size_t kErr = -1; constexpr static size_t kErr = -1;
std::thread([this] { std::thread watch_dog([this] {
while (true) { while (true) {
auto logd_size = GetByteProp(kLogdSizeProp); auto logd_size = GetByteProp(kLogdSizeProp);
auto logd_tag = GetStrProp(kLogdTagProp); auto logd_tag = GetStrProp(kLogdTagProp);
@ -276,8 +276,12 @@ void Logcat::EnsureLogWatchDog() {
} }
if (!__system_property_wait(pi, serial, &serial, nullptr)) break; if (!__system_property_wait(pi, serial, &serial, nullptr)) break;
if (pi != nullptr) Log("\nResetting log settings\n"); if (pi != nullptr) Log("\nResetting log settings\n");
else std::this_thread::sleep_for(1s);
// log tag prop was not found; to avoid frequently trigger wait, sleep for a while
} }
}).detach(); });
pthread_setname_np(watch_dog.native_handle(), "watchdog");
watch_dog.detach();
} }
void Logcat::Run() { void Logcat::Run() {