| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 <windows.h> | 7 #include <windows.h> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 | 10 |
| (...skipping 29 matching lines...) Expand all Loading... |
| 40 // Atomically test-and-set the tls_key. If the key is TLS_OUT_OF_INDEXES, | 40 // Atomically test-and-set the tls_key. If the key is TLS_OUT_OF_INDEXES, |
| 41 // go ahead and set it. Otherwise, do nothing, as another | 41 // go ahead and set it. Otherwise, do nothing, as another |
| 42 // thread already did our dirty work. | 42 // thread already did our dirty work. |
| 43 if (InterlockedCompareExchange(&tls_key_, value, TLS_OUT_OF_INDEXES) != | 43 if (InterlockedCompareExchange(&tls_key_, value, TLS_OUT_OF_INDEXES) != |
| 44 TLS_OUT_OF_INDEXES) { | 44 TLS_OUT_OF_INDEXES) { |
| 45 // We've been shortcut. Another thread replaced tls_key_ first so we need | 45 // We've been shortcut. Another thread replaced tls_key_ first so we need |
| 46 // to destroy our index and use the one the other thread got first. | 46 // to destroy our index and use the one the other thread got first. |
| 47 TlsFree(value); | 47 TlsFree(value); |
| 48 } | 48 } |
| 49 } | 49 } |
| 50 DCHECK(TlsGetValue(tls_key_) == NULL); | 50 DCHECK(!TlsGetValue(tls_key_)); |
| 51 | 51 |
| 52 // Create an array to store our data. | 52 // Create an array to store our data. |
| 53 void** tls_data = new void*[kThreadLocalStorageSize]; | 53 void** tls_data = new void*[kThreadLocalStorageSize]; |
| 54 memset(tls_data, 0, sizeof(void*[kThreadLocalStorageSize])); | 54 memset(tls_data, 0, sizeof(void*[kThreadLocalStorageSize])); |
| 55 TlsSetValue(tls_key_, tls_data); | 55 TlsSetValue(tls_key_, tls_data); |
| 56 return tls_data; | 56 return tls_data; |
| 57 } | 57 } |
| 58 | 58 |
| 59 ThreadLocalStorage::Slot::Slot(TLSDestructorFunc destructor) | 59 ThreadLocalStorage::Slot::Slot(TLSDestructorFunc destructor) |
| 60 : initialized_(false), | 60 : initialized_(false), |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 190 #else // _WIN64 | 190 #else // _WIN64 |
| 191 | 191 |
| 192 #pragma data_seg(".CRT$XLB") | 192 #pragma data_seg(".CRT$XLB") |
| 193 PIMAGE_TLS_CALLBACK p_thread_callback_base = OnThreadExit; | 193 PIMAGE_TLS_CALLBACK p_thread_callback_base = OnThreadExit; |
| 194 | 194 |
| 195 // Reset the default section. | 195 // Reset the default section. |
| 196 #pragma data_seg() | 196 #pragma data_seg() |
| 197 | 197 |
| 198 #endif // _WIN64 | 198 #endif // _WIN64 |
| 199 } // extern "C" | 199 } // extern "C" |
| OLD | NEW |