From ee747e7dfa543cf77096d348aa6674365a9975c7 Mon Sep 17 00:00:00 2001 From: Tom Cherry Date: Fri, 20 Dec 2019 16:06:34 -0800 Subject: [PATCH] liblog: don't destroy global mutexes Some objects may log when they're destructed, so don't destroy the global std::mutex in fake_log_device.cpp. Test: AAPT works with a log in VectorImpl::finish_vector() Change-Id: Ie5a0ac9fc4e6a137e9516059a831e499d55d5ddb --- liblog/Android.bp | 5 ++++- liblog/fake_log_device.cpp | 7 ++++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/liblog/Android.bp b/liblog/Android.bp index de0c636f0..bab57c084 100644 --- a/liblog/Android.bp +++ b/liblog/Android.bp @@ -95,7 +95,10 @@ cc_library { }, }, - header_libs: ["liblog_headers"], + header_libs: [ + "libbase_headers", + "liblog_headers", + ], export_header_lib_headers: ["liblog_headers"], stubs: { diff --git a/liblog/fake_log_device.cpp b/liblog/fake_log_device.cpp index fb3b9bc72..2ec639358 100644 --- a/liblog/fake_log_device.cpp +++ b/liblog/fake_log_device.cpp @@ -31,6 +31,7 @@ #include +#include #include #include #include @@ -72,7 +73,7 @@ typedef struct LogState { } LogState; static LogState log_state; -static std::mutex fake_log_mutex; +static android::base::NoDestructor fake_log_mutex; /* * Configure logging based on ANDROID_LOG_TAGS environment variable. We @@ -457,7 +458,7 @@ static int FakeWrite(log_id_t log_id, struct timespec*, struct iovec* vector, si * Also guarantees that only one thread is in showLog() at a given * time (if it matters). */ - auto lock = std::lock_guard{fake_log_mutex}; + auto lock = std::lock_guard{*fake_log_mutex}; if (!log_state.initialized) { InitializeLogStateLocked(); @@ -519,7 +520,7 @@ static int FakeWrite(log_id_t log_id, struct timespec*, struct iovec* vector, si * help debug HOST tools ... */ static void FakeClose() { - auto lock = std::lock_guard{fake_log_mutex}; + auto lock = std::lock_guard{*fake_log_mutex}; memset(&log_state, 0, sizeof(log_state)); }