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

Unified Diff: base/i18n/rtl.cc

Issue 2877983004: [TSAN] Fix TSAN error in i18n RTL. (Closed)
Patch Set: fix typo in type name Created 3 years, 7 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 2b6bf37706fd4ad52b28024427fa0451fc121c9d..07fd9642d37d203689c86e2083cf6052f1cf515e 100644
--- a/base/i18n/rtl.cc
+++ b/base/i18n/rtl.cc
@@ -9,6 +9,7 @@
#include <algorithm>
+#include "base/atomicops.h"
#include "base/command_line.h"
#include "base/files/file_path.h"
#include "base/i18n/base_i18n_switches.h"
@@ -113,7 +114,8 @@ namespace base {
namespace i18n {
// Represents the locale-specific ICU text direction.
-static TextDirection g_icu_text_direction = UNKNOWN_DIRECTION;
+static subtle::Atomic32 g_icu_text_direction =
+ static_cast<subtle::Atomic32>(UNKNOWN_DIRECTION);
// Convert the ICU default locale to a string.
std::string GetConfiguredLocale() {
@@ -162,7 +164,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;
+ subtle::Release_Store(
+ &g_icu_text_direction,
+ static_cast<subtle::Atomic32>(
+ GetTextDirectionForLocaleInStartUp(locale.getName())));
}
bool IsRTL() {
@@ -170,11 +175,11 @@ bool IsRTL() {
}
bool ICUIsRTL() {
- if (g_icu_text_direction == UNKNOWN_DIRECTION) {
- const icu::Locale& locale = icu::Locale::getDefault();
- g_icu_text_direction = GetTextDirectionForLocaleInStartUp(locale.getName());
- }
- return g_icu_text_direction == RIGHT_TO_LEFT;
+ // Note: There is still a race if this is executed between the
+ // icu::Locale::setDefault and the g_icu_text_direction store
+ // that happens in SetICUDefaultLocale.
+ return static_cast<TextDirection>(
+ subtle::Acquire_Load(&g_icu_text_direction)) == RIGHT_TO_LEFT;
}
TextDirection GetTextDirectionForLocaleInStartUp(const char* locale_name) {
« 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