OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "base/threading/thread_local_storage.h" | 5 #include "base/threading/thread_local_storage.h" |
6 | 6 |
7 #include "base/atomicops.h" | 7 #include "base/atomicops.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 | 9 |
10 using base::internal::PlatformThreadLocalStorage; | 10 using base::internal::PlatformThreadLocalStorage; |
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
164 // Remove our stack allocated vector. | 164 // Remove our stack allocated vector. |
165 PlatformThreadLocalStorage::SetTLSValue(key, NULL); | 165 PlatformThreadLocalStorage::SetTLSValue(key, NULL); |
166 } | 166 } |
167 | 167 |
168 } // namespace | 168 } // namespace |
169 | 169 |
170 namespace base { | 170 namespace base { |
171 | 171 |
172 namespace internal { | 172 namespace internal { |
173 | 173 |
174 #if defined(OS_WIN) | 174 #if defined(OS_POSIX) |
175 void PlatformThreadLocalStorage::OnThreadExit() { | |
176 PlatformThreadLocalStorage::TLSKey key = | |
177 base::subtle::NoBarrier_Load(&g_native_tls_key); | |
178 if (key == PlatformThreadLocalStorage::TLS_KEY_OUT_OF_INDEXES) | |
179 return; | |
180 void *tls_data = GetTLSValue(key); | |
181 // Maybe we have never initialized TLS for this thread. | |
182 if (!tls_data) | |
183 return; | |
184 OnThreadExitInternal(tls_data); | |
185 } | |
186 #elif defined(OS_POSIX) | |
187 void PlatformThreadLocalStorage::OnThreadExit(void* value) { | 175 void PlatformThreadLocalStorage::OnThreadExit(void* value) { |
188 OnThreadExitInternal(value); | 176 OnThreadExitInternal(value); |
189 } | 177 } |
190 #endif // defined(OS_WIN) | 178 #endif // defined(OS_POSIX) |
191 | 179 |
192 } // namespace internal | 180 } // namespace internal |
193 | 181 |
194 ThreadLocalStorage::Slot::Slot(TLSDestructorFunc destructor) { | 182 ThreadLocalStorage::Slot::Slot(TLSDestructorFunc destructor) { |
195 initialized_ = false; | 183 initialized_ = false; |
196 slot_ = 0; | 184 slot_ = 0; |
197 Initialize(destructor); | 185 Initialize(destructor); |
198 } | 186 } |
199 | 187 |
200 void ThreadLocalStorage::StaticSlot::Initialize(TLSDestructorFunc destructor) { | 188 void ThreadLocalStorage::StaticSlot::Initialize(TLSDestructorFunc destructor) { |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
240 PlatformThreadLocalStorage::GetTLSValue( | 228 PlatformThreadLocalStorage::GetTLSValue( |
241 base::subtle::NoBarrier_Load(&g_native_tls_key))); | 229 base::subtle::NoBarrier_Load(&g_native_tls_key))); |
242 if (!tls_data) | 230 if (!tls_data) |
243 tls_data = ConstructTlsVector(); | 231 tls_data = ConstructTlsVector(); |
244 DCHECK_GT(slot_, 0); | 232 DCHECK_GT(slot_, 0); |
245 DCHECK_LT(slot_, kThreadLocalStorageSize); | 233 DCHECK_LT(slot_, kThreadLocalStorageSize); |
246 tls_data[slot_] = value; | 234 tls_data[slot_] = value; |
247 } | 235 } |
248 | 236 |
249 } // namespace base | 237 } // namespace base |
OLD | NEW |