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 13 matching lines...) Expand all Loading... |
24 // g_last_used_tls_key is the high-water-mark of allocated thread local storage. | 24 // g_last_used_tls_key is the high-water-mark of allocated thread local storage. |
25 // Each allocation is an index into our g_tls_destructors[]. Each such index is | 25 // Each allocation is an index into our g_tls_destructors[]. Each such index is |
26 // assigned to the instance variable slot_ in a ThreadLocalStorage::Slot | 26 // assigned to the instance variable slot_ in a ThreadLocalStorage::Slot |
27 // instance. We reserve the value slot_ == 0 to indicate that the corresponding | 27 // instance. We reserve the value slot_ == 0 to indicate that the corresponding |
28 // instance of ThreadLocalStorage::Slot has been freed (i.e., destructor called, | 28 // instance of ThreadLocalStorage::Slot has been freed (i.e., destructor called, |
29 // etc.). This reserved use of 0 is then stated as the initial value of | 29 // etc.). This reserved use of 0 is then stated as the initial value of |
30 // g_last_used_tls_key, so that the first issued index will be 1. | 30 // g_last_used_tls_key, so that the first issued index will be 1. |
31 base::subtle::Atomic32 g_last_used_tls_key = 0; | 31 base::subtle::Atomic32 g_last_used_tls_key = 0; |
32 | 32 |
33 // The maximum number of 'slots' in our thread local storage stack. | 33 // The maximum number of 'slots' in our thread local storage stack. |
34 const int kThreadLocalStorageSize = 64; | 34 const int kThreadLocalStorageSize = 256; |
35 | 35 |
36 // The maximum number of times to try to clear slots by calling destructors. | 36 // The maximum number of times to try to clear slots by calling destructors. |
37 // Use pthread naming convention for clarity. | 37 // Use pthread naming convention for clarity. |
38 const int kMaxDestructorIterations = kThreadLocalStorageSize; | 38 const int kMaxDestructorIterations = kThreadLocalStorageSize; |
39 | 39 |
40 // An array of destructor function pointers for the slots. If a slot has a | 40 // An array of destructor function pointers for the slots. If a slot has a |
41 // destructor, it will be stored in its corresponding entry in this array. | 41 // destructor, it will be stored in its corresponding entry in this array. |
42 // The elements are volatile to ensure that when the compiler reads the value | 42 // The elements are volatile to ensure that when the compiler reads the value |
43 // to potentially call the destructor, it does so once, and that value is tested | 43 // to potentially call the destructor, it does so once, and that value is tested |
44 // for null-ness and then used. Yes, that would be a weird de-optimization, | 44 // for null-ness and then used. Yes, that would be a weird de-optimization, |
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
241 PlatformThreadLocalStorage::GetTLSValue( | 241 PlatformThreadLocalStorage::GetTLSValue( |
242 base::subtle::NoBarrier_Load(&g_native_tls_key))); | 242 base::subtle::NoBarrier_Load(&g_native_tls_key))); |
243 if (!tls_data) | 243 if (!tls_data) |
244 tls_data = ConstructTlsVector(); | 244 tls_data = ConstructTlsVector(); |
245 DCHECK_GT(slot_, 0); | 245 DCHECK_GT(slot_, 0); |
246 DCHECK_LT(slot_, kThreadLocalStorageSize); | 246 DCHECK_LT(slot_, kThreadLocalStorageSize); |
247 tls_data[slot_] = value; | 247 tls_data[slot_] = value; |
248 } | 248 } |
249 | 249 |
250 } // namespace base | 250 } // namespace base |
OLD | NEW |