OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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/thread_local_storage.h" | 5 #include "base/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 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
93 | 93 |
94 void ThreadLocalStorage::Slot::Set(void* value) { | 94 void ThreadLocalStorage::Slot::Set(void* value) { |
95 void** tls_data = static_cast<void**>(TlsGetValue(tls_key_)); | 95 void** tls_data = static_cast<void**>(TlsGetValue(tls_key_)); |
96 if (!tls_data) | 96 if (!tls_data) |
97 tls_data = ThreadLocalStorage::Initialize(); | 97 tls_data = ThreadLocalStorage::Initialize(); |
98 DCHECK(slot_ >= 0 && slot_ < kThreadLocalStorageSize); | 98 DCHECK(slot_ >= 0 && slot_ < kThreadLocalStorageSize); |
99 tls_data[slot_] = value; | 99 tls_data[slot_] = value; |
100 } | 100 } |
101 | 101 |
102 void ThreadLocalStorage::ThreadExit() { | 102 void ThreadLocalStorage::ThreadExit() { |
| 103 if (tls_key_ == TLS_OUT_OF_INDEXES) |
| 104 return; |
| 105 |
103 void** tls_data = static_cast<void**>(TlsGetValue(tls_key_)); | 106 void** tls_data = static_cast<void**>(TlsGetValue(tls_key_)); |
104 | 107 |
105 // Maybe we have never initialized TLS for this thread. | 108 // Maybe we have never initialized TLS for this thread. |
106 if (!tls_data) | 109 if (!tls_data) |
107 return; | 110 return; |
108 | 111 |
109 for (int slot = 0; slot < tls_max_; slot++) { | 112 for (int slot = 0; slot < tls_max_; slot++) { |
110 if (tls_destructors_[slot] != NULL) { | 113 if (tls_destructors_[slot] != NULL) { |
111 void* value = tls_data[slot]; | 114 void* value = tls_data[slot]; |
112 tls_destructors_[slot](value); | 115 tls_destructors_[slot](value); |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
175 #else // _WIN64 | 178 #else // _WIN64 |
176 | 179 |
177 #pragma data_seg(".CRT$XLB") | 180 #pragma data_seg(".CRT$XLB") |
178 PIMAGE_TLS_CALLBACK p_thread_callback = OnThreadExit; | 181 PIMAGE_TLS_CALLBACK p_thread_callback = OnThreadExit; |
179 | 182 |
180 // Reset the default section. | 183 // Reset the default section. |
181 #pragma data_seg() | 184 #pragma data_seg() |
182 | 185 |
183 #endif // _WIN64 | 186 #endif // _WIN64 |
184 | 187 |
OLD | NEW |