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 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
190 #endif // defined(OS_WIN) | 190 #endif // defined(OS_WIN) |
191 | 191 |
192 } // namespace internal | 192 } // namespace internal |
193 | 193 |
194 ThreadLocalStorage::Slot::Slot(TLSDestructorFunc destructor) { | 194 ThreadLocalStorage::Slot::Slot(TLSDestructorFunc destructor) { |
195 initialized_ = false; | 195 initialized_ = false; |
196 slot_ = 0; | 196 slot_ = 0; |
197 Initialize(destructor); | 197 Initialize(destructor); |
198 } | 198 } |
199 | 199 |
200 bool ThreadLocalStorage::StaticSlot::Initialize(TLSDestructorFunc destructor) { | 200 void ThreadLocalStorage::StaticSlot::Initialize(TLSDestructorFunc destructor) { |
201 PlatformThreadLocalStorage::TLSKey key = | 201 PlatformThreadLocalStorage::TLSKey key = |
202 base::subtle::NoBarrier_Load(&g_native_tls_key); | 202 base::subtle::NoBarrier_Load(&g_native_tls_key); |
203 if (key == PlatformThreadLocalStorage::TLS_KEY_OUT_OF_INDEXES || | 203 if (key == PlatformThreadLocalStorage::TLS_KEY_OUT_OF_INDEXES || |
204 !PlatformThreadLocalStorage::GetTLSValue(key)) | 204 !PlatformThreadLocalStorage::GetTLSValue(key)) |
205 ConstructTlsVector(); | 205 ConstructTlsVector(); |
206 | 206 |
207 // Grab a new slot. | 207 // Grab a new slot. |
208 slot_ = base::subtle::NoBarrier_AtomicIncrement(&g_last_used_tls_key, 1); | 208 slot_ = base::subtle::NoBarrier_AtomicIncrement(&g_last_used_tls_key, 1); |
209 DCHECK_GT(slot_, 0); | 209 DCHECK_GT(slot_, 0); |
210 CHECK_LT(slot_, kThreadLocalStorageSize); | 210 CHECK_LT(slot_, kThreadLocalStorageSize); |
211 | 211 |
212 // Setup our destructor. | 212 // Setup our destructor. |
213 g_tls_destructors[slot_] = destructor; | 213 g_tls_destructors[slot_] = destructor; |
214 initialized_ = true; | 214 initialized_ = true; |
215 return true; | |
216 } | 215 } |
217 | 216 |
218 void ThreadLocalStorage::StaticSlot::Free() { | 217 void ThreadLocalStorage::StaticSlot::Free() { |
219 // At this time, we don't reclaim old indices for TLS slots. | 218 // At this time, we don't reclaim old indices for TLS slots. |
220 // So all we need to do is wipe the destructor. | 219 // So all we need to do is wipe the destructor. |
221 DCHECK_GT(slot_, 0); | 220 DCHECK_GT(slot_, 0); |
222 DCHECK_LT(slot_, kThreadLocalStorageSize); | 221 DCHECK_LT(slot_, kThreadLocalStorageSize); |
223 g_tls_destructors[slot_] = NULL; | 222 g_tls_destructors[slot_] = NULL; |
224 slot_ = 0; | 223 slot_ = 0; |
225 initialized_ = false; | 224 initialized_ = false; |
(...skipping 15 matching lines...) Expand all Loading... |
241 PlatformThreadLocalStorage::GetTLSValue( | 240 PlatformThreadLocalStorage::GetTLSValue( |
242 base::subtle::NoBarrier_Load(&g_native_tls_key))); | 241 base::subtle::NoBarrier_Load(&g_native_tls_key))); |
243 if (!tls_data) | 242 if (!tls_data) |
244 tls_data = ConstructTlsVector(); | 243 tls_data = ConstructTlsVector(); |
245 DCHECK_GT(slot_, 0); | 244 DCHECK_GT(slot_, 0); |
246 DCHECK_LT(slot_, kThreadLocalStorageSize); | 245 DCHECK_LT(slot_, kThreadLocalStorageSize); |
247 tls_data[slot_] = value; | 246 tls_data[slot_] = value; |
248 } | 247 } |
249 | 248 |
250 } // namespace base | 249 } // namespace base |
OLD | NEW |