Merge "liblog: don't destroy global mutexes"

This commit is contained in:
Tom Cherry 2019-12-27 21:55:59 +00:00 committed by Gerrit Code Review
commit 0962561c9b
2 changed files with 8 additions and 4 deletions

View File

@ -95,7 +95,10 @@ cc_library {
},
},
header_libs: ["liblog_headers"],
header_libs: [
"libbase_headers",
"liblog_headers",
],
export_header_lib_headers: ["liblog_headers"],
stubs: {

View File

@ -31,6 +31,7 @@
#include <mutex>
#include <android-base/no_destructor.h>
#include <android/log.h>
#include <log/log_id.h>
#include <log/logprint.h>
@ -72,7 +73,7 @@ typedef struct LogState {
} LogState;
static LogState log_state;
static std::mutex fake_log_mutex;
static android::base::NoDestructor<std::mutex> 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));
}