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

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

liblog: minimum_log_priority should be atomic

In case multiple threads try to reference this variable while it is
being set, it should be atomic so that all threads always see a valid
value.

Bug: 150898477
Test: liblog, libbase unit tests
Change-Id: If6c9e291f2471b96a752dc6e76e3e63458b71391
parent 3a4e3825
Loading
Loading
Loading
Loading
+3 −4
Original line number Diff line number Diff line
@@ -27,6 +27,7 @@
#include <android/set_abort_message.h>
#endif

#include <atomic>
#include <shared_mutex>

#include <android-base/errno_restorer.h>
@@ -148,11 +149,9 @@ void __android_log_set_default_tag(const char* tag) {
  GetDefaultTag().assign(tag, 0, LOGGER_ENTRY_MAX_PAYLOAD);
}

static int minimum_log_priority = ANDROID_LOG_DEFAULT;
static std::atomic_int minimum_log_priority = ANDROID_LOG_DEFAULT;
int __android_log_set_minimum_priority(int priority) {
  int old_minimum_log_priority = minimum_log_priority;
  minimum_log_priority = priority;
  return old_minimum_log_priority;
  return minimum_log_priority.exchange(priority, std::memory_order_relaxed);
}

int __android_log_get_minimum_priority() {