[TSAN] Fix TSAN error in i18n RTL.

Use an atomic to protect the global g_icu_text_direction cached value
from multiple readers/writers.

Also reduce acccess to g_icu_text_diretion so it only has a single write
location (in SetICUDefaultLocal) and a single read location (ICUIsRTL),
to simplify the race-y-ness.

Outside of test code, SetICUDefaultLocal is only used in two locations:
ppapi_plugin_main.cc and l10n_util.cc, whereas IsRTL is used in >100
places outside of test code, so it seemed reasonable to move the heavy
logic (updating g_icu_text_direction when it changes) into what I imagine to be
a function that is called rarely and let the one that is used a lot
(IsRTL/ICUIsRTL) just do a simple read.

This still still leaves a race condition in that IsRTL may give in
inaccurate result if SetICUDefaultLocale is executed at the same time.
In particular, IsRTL may return the value for the previously set default
locale after the default locale has been updated.

BUG=695929
TEST=cast_shell_browsertests under TSAN before/after

Review-Url: https://codereview.chromium.org/2877983004
Cr-Commit-Position: refs/heads/master@{#472890}


CrOS-Libchrome-Original-Commit: 89c24d4a46c1f0e7ad03891a659e6d23dc776c36
1 file changed
tree: ca585f13e4b97f0712ac134563d6bc3f7c7602a4
  1. base/
  2. build/
  3. components/
  4. dbus/
  5. device/
  6. ipc/
  7. mojo/
  8. testing/
  9. third_party/
  10. ui/