From bbb16022c7d13e9cfc628bf0f3de4b40a3670679 Mon Sep 17 00:00:00 2001 From: Tom Cherry Date: Mon, 9 Mar 2020 12:43:18 -0700 Subject: [PATCH] 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 --- liblog/logger_write.cpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/liblog/logger_write.cpp b/liblog/logger_write.cpp index 1b6b0c697..0dbb94f09 100644 --- a/liblog/logger_write.cpp +++ b/liblog/logger_write.cpp @@ -27,6 +27,7 @@ #include #endif +#include #include #include @@ -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() {