1*635a8641SAndroid Build Coastguard WorkerFrom 28a638ff22f598f6aa9388db6a4cf13fe9f11644 Mon Sep 17 00:00:00 2001
2*635a8641SAndroid Build Coastguard WorkerFrom: Hirokazu Honda <[email protected]>
3*635a8641SAndroid Build Coastguard WorkerDate: Wed, 1 Aug 2018 17:03:18 +0900
4*635a8641SAndroid Build Coastguard WorkerSubject: [PATCH] ThreadLocalStorage: Add a function to destroy pthread key
5*635a8641SAndroid Build Coastguard Worker used in libchrome
6*635a8641SAndroid Build Coastguard Worker
7*635a8641SAndroid Build Coastguard WorkerMojoProcessSupport needs to destroy pthread key which is globally used in libchrome. The key is
8*635a8641SAndroid Build Coastguard Workerstored in a local variable in thread_local_storage.cc.
9*635a8641SAndroid Build Coastguard WorkerThis adds a function to destroy the key so that MojoProcessSupport can do it.
10*635a8641SAndroid Build Coastguard Worker
11*635a8641SAndroid Build Coastguard WorkerBug: 110722333
12*635a8641SAndroid Build Coastguard WorkerTest: No crash in opening DRMInfo.app
13*635a8641SAndroid Build Coastguard WorkerTest: PlayStore still works
14*635a8641SAndroid Build Coastguard WorkerTest: cheets_ContainerSmokeTest and cheets_LoginScreen
15*635a8641SAndroid Build Coastguard WorkerChange-Id: Ib10c83deb5f7ef141d4ab9883e0d2c31d422a1b1
16*635a8641SAndroid Build Coastguard Worker---
17*635a8641SAndroid Build Coastguard Worker base/threading/thread_local_storage.cc | 11 +++++++++++
18*635a8641SAndroid Build Coastguard Worker base/threading/thread_local_storage.h  |  7 +++++++
19*635a8641SAndroid Build Coastguard Worker 2 files changed, 18 insertions(+)
20*635a8641SAndroid Build Coastguard Worker
21*635a8641SAndroid Build Coastguard Workerdiff --git a/base/threading/thread_local_storage.cc b/base/threading/thread_local_storage.cc
22*635a8641SAndroid Build Coastguard Workerindex 48c1dd5..90ae69e 100644
23*635a8641SAndroid Build Coastguard Worker--- a/base/threading/thread_local_storage.cc
24*635a8641SAndroid Build Coastguard Worker+++ b/base/threading/thread_local_storage.cc
25*635a8641SAndroid Build Coastguard Worker@@ -247,6 +247,17 @@ void PlatformThreadLocalStorage::OnThreadExit() {
26*635a8641SAndroid Build Coastguard Worker void PlatformThreadLocalStorage::OnThreadExit(void* value) {
27*635a8641SAndroid Build Coastguard Worker   OnThreadExitInternal(static_cast<TlsVectorEntry*>(value));
28*635a8641SAndroid Build Coastguard Worker }
29*635a8641SAndroid Build Coastguard Worker+
30*635a8641SAndroid Build Coastguard Worker+// static
31*635a8641SAndroid Build Coastguard Worker+void PlatformThreadLocalStorage::ForceFreeTLS() {
32*635a8641SAndroid Build Coastguard Worker+  PlatformThreadLocalStorage::TLSKey key =
33*635a8641SAndroid Build Coastguard Worker+      base::subtle::NoBarrier_AtomicExchange(
34*635a8641SAndroid Build Coastguard Worker+          &g_native_tls_key,
35*635a8641SAndroid Build Coastguard Worker+          PlatformThreadLocalStorage::TLS_KEY_OUT_OF_INDEXES);
36*635a8641SAndroid Build Coastguard Worker+  if (key == PlatformThreadLocalStorage::TLS_KEY_OUT_OF_INDEXES)
37*635a8641SAndroid Build Coastguard Worker+    return;
38*635a8641SAndroid Build Coastguard Worker+  PlatformThreadLocalStorage::FreeTLS(key);
39*635a8641SAndroid Build Coastguard Worker+}
40*635a8641SAndroid Build Coastguard Worker #endif  // defined(OS_WIN)
41*635a8641SAndroid Build Coastguard Worker
42*635a8641SAndroid Build Coastguard Worker }  // namespace internal
43*635a8641SAndroid Build Coastguard Workerdiff --git a/base/threading/thread_local_storage.h b/base/threading/thread_local_storage.h
44*635a8641SAndroid Build Coastguard Workerindex fd2a789..c5c7759 100644
45*635a8641SAndroid Build Coastguard Worker--- a/base/threading/thread_local_storage.h
46*635a8641SAndroid Build Coastguard Worker+++ b/base/threading/thread_local_storage.h
47*635a8641SAndroid Build Coastguard Worker@@ -75,6 +75,13 @@ class BASE_EXPORT PlatformThreadLocalStorage {
48*635a8641SAndroid Build Coastguard Worker   // GetTLSValue() to retrieve the value of slot as it has already been reset
49*635a8641SAndroid Build Coastguard Worker   // in Posix.
50*635a8641SAndroid Build Coastguard Worker   static void OnThreadExit(void* value);
51*635a8641SAndroid Build Coastguard Worker+  // Normally, Chrome runs as a process, so freeing the TLS is not needed since
52*635a8641SAndroid Build Coastguard Worker+  // the OS will perform that while it's reclaiming the process' memory upon
53*635a8641SAndroid Build Coastguard Worker+  // termination. If, however, this code is used inside a library that is
54*635a8641SAndroid Build Coastguard Worker+  // dynamically loaded and unloaded, the consumer is responsible for calling
55*635a8641SAndroid Build Coastguard Worker+  // this after all Chrome threads have stopped and prior to unloading the
56*635a8641SAndroid Build Coastguard Worker+  // library.
57*635a8641SAndroid Build Coastguard Worker+  static void ForceFreeTLS();
58*635a8641SAndroid Build Coastguard Worker #endif
59*635a8641SAndroid Build Coastguard Worker };
60*635a8641SAndroid Build Coastguard Worker
61*635a8641SAndroid Build Coastguard Worker--
62*635a8641SAndroid Build Coastguard Worker2.18.0.345.g5c9ce644c3-goog
63*635a8641SAndroid Build Coastguard Worker
64