Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(221)

Side by Side Diff: base/threading/thread_local_storage.cc

Issue 379503002: Change g_native_tls_key to be 32-bit wide to match underlying type. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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;
11 11
12 namespace { 12 namespace {
13 // In order to make TLS destructors work, we need to keep around a function 13 // In order to make TLS destructors work, we need to keep around a function
14 // pointer to the destructor for each slot. We keep this array of pointers in a 14 // pointer to the destructor for each slot. We keep this array of pointers in a
15 // global (static) array. 15 // global (static) array.
16 // We use the single OS-level TLS slot (giving us one pointer per thread) to 16 // We use the single OS-level TLS slot (giving us one pointer per thread) to
17 // hold a pointer to a per-thread array (table) of slots that we allocate to 17 // hold a pointer to a per-thread array (table) of slots that we allocate to
18 // Chromium consumers. 18 // Chromium consumers.
19 19
20 // g_native_tls_key is the one native TLS that we use. It stores our table. 20 // g_native_tls_key is the one native TLS that we use. It stores our table.
21 base::subtle::AtomicWord g_native_tls_key = 21 base::subtle::Atomic32 g_native_tls_key =
22 PlatformThreadLocalStorage::TLS_KEY_OUT_OF_INDEXES; 22 PlatformThreadLocalStorage::TLS_KEY_OUT_OF_INDEXES;
23 23
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;
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after
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
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698