Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit ee747e7d authored by Tom Cherry's avatar Tom Cherry
Browse files

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
parent 264a37d1
Loading
Loading
Loading
Loading
+4 −1
Original line number Diff line number Diff line
@@ -95,7 +95,10 @@ cc_library {
        },
    },

    header_libs: ["liblog_headers"],
    header_libs: [
        "libbase_headers",
        "liblog_headers",
    ],
    export_header_lib_headers: ["liblog_headers"],

    stubs: {
+4 −3
Original line number Diff line number Diff line
@@ -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));
}