Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3248)

Unified Diff: base/i18n/rtl.cc

Issue 2716003002: [TSAN] Fix data race with base::i18n text direction. (Closed)
Patch Set: Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/i18n/rtl.cc
diff --git a/base/i18n/rtl.cc b/base/i18n/rtl.cc
index 095d66c6d8af13a9846e70ddc4fdf650410d2d03..28fa0b087c2395461161a9302f84cfd3aa5611d7 100644
--- a/base/i18n/rtl.cc
+++ b/base/i18n/rtl.cc
@@ -12,12 +12,14 @@
#include "base/command_line.h"
#include "base/files/file_path.h"
#include "base/i18n/base_i18n_switches.h"
+#include "base/lazy_instance.h"
#include "base/logging.h"
#include "base/macros.h"
#include "base/strings/string_split.h"
#include "base/strings/string_util.h"
#include "base/strings/sys_string_conversions.h"
#include "base/strings/utf_string_conversions.h"
+#include "base/synchronization/lock.h"
#include "build/build_config.h"
#include "third_party/icu/source/common/unicode/locid.h"
#include "third_party/icu/source/common/unicode/uchar.h"
@@ -101,6 +103,8 @@ namespace base {
namespace i18n {
// Represents the locale-specific ICU text direction.
+static base::LazyInstance<base::Lock>::Leaky g_icu_text_direction_lock =
+ LAZY_INSTANCE_INITIALIZER;
static TextDirection g_icu_text_direction = UNKNOWN_DIRECTION;
// Convert the ICU default locale to a string.
@@ -150,7 +154,10 @@ void SetICUDefaultLocale(const std::string& locale_string) {
// presence of actual locale data). However,
// it does not hurt to have it as a sanity check.
DCHECK(U_SUCCESS(error_code));
- g_icu_text_direction = UNKNOWN_DIRECTION;
+ {
+ base::AutoLock lock(g_icu_text_direction_lock.Get());
+ g_icu_text_direction = UNKNOWN_DIRECTION;
+ }
}
bool IsRTL() {
@@ -158,6 +165,7 @@ bool IsRTL() {
}
bool ICUIsRTL() {
+ base::AutoLock lock(g_icu_text_direction_lock.Get());
if (g_icu_text_direction == UNKNOWN_DIRECTION) {
const icu::Locale& locale = icu::Locale::getDefault();
g_icu_text_direction = GetTextDirectionForLocaleInStartUp(locale.getName());
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698