OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #ifndef BASE_THREADING_THREAD_LOCAL_STORAGE_H_ | 5 #ifndef BASE_THREADING_THREAD_LOCAL_STORAGE_H_ |
6 #define BASE_THREADING_THREAD_LOCAL_STORAGE_H_ | 6 #define BASE_THREADING_THREAD_LOCAL_STORAGE_H_ |
7 | 7 |
| 8 #include <stdint.h> |
| 9 |
8 #include "base/atomicops.h" | 10 #include "base/atomicops.h" |
9 #include "base/base_export.h" | 11 #include "base/base_export.h" |
10 #include "base/macros.h" | 12 #include "base/macros.h" |
11 #include "build/build_config.h" | 13 #include "build/build_config.h" |
12 | 14 |
13 #if defined(OS_WIN) | 15 #if defined(OS_WIN) |
14 #include <windows.h> | 16 #include <windows.h> |
15 #elif defined(OS_POSIX) | 17 #elif defined(OS_POSIX) |
16 #include <pthread.h> | 18 #include <pthread.h> |
17 #endif | 19 #endif |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
116 // value 'value'. | 118 // value 'value'. |
117 void Set(void* value); | 119 void Set(void* value); |
118 | 120 |
119 bool initialized() const { | 121 bool initialized() const { |
120 return base::subtle::Acquire_Load(&initialized_) != 0; | 122 return base::subtle::Acquire_Load(&initialized_) != 0; |
121 } | 123 } |
122 | 124 |
123 // The internals of this struct should be considered private. | 125 // The internals of this struct should be considered private. |
124 base::subtle::Atomic32 initialized_; | 126 base::subtle::Atomic32 initialized_; |
125 int slot_; | 127 int slot_; |
| 128 uint32_t version_; |
126 }; | 129 }; |
127 | 130 |
128 // A convenience wrapper around StaticSlot with a constructor. Can be used | 131 // A convenience wrapper around StaticSlot with a constructor. Can be used |
129 // as a member variable. | 132 // as a member variable. |
130 class BASE_EXPORT Slot { | 133 class BASE_EXPORT Slot { |
131 public: | 134 public: |
132 explicit Slot(TLSDestructorFunc destructor = NULL); | 135 explicit Slot(TLSDestructorFunc destructor = NULL); |
133 ~Slot(); | 136 ~Slot(); |
134 | 137 |
135 // Get the thread-local value stored in this slot. | 138 // Get the thread-local value stored in this slot. |
136 // Values are guaranteed to initially be zero. | 139 // Values are guaranteed to initially be zero. |
137 void* Get() const; | 140 void* Get() const; |
138 | 141 |
139 // Set the slot's thread-local value to |value|. | 142 // Set the slot's thread-local value to |value|. |
140 void Set(void* value); | 143 void Set(void* value); |
141 | 144 |
142 private: | 145 private: |
143 StaticSlot tls_slot_; | 146 StaticSlot tls_slot_; |
144 | 147 |
145 DISALLOW_COPY_AND_ASSIGN(Slot); | 148 DISALLOW_COPY_AND_ASSIGN(Slot); |
146 }; | 149 }; |
147 | 150 |
148 private: | 151 private: |
149 DISALLOW_COPY_AND_ASSIGN(ThreadLocalStorage); | 152 DISALLOW_COPY_AND_ASSIGN(ThreadLocalStorage); |
150 }; | 153 }; |
151 | 154 |
152 } // namespace base | 155 } // namespace base |
153 | 156 |
154 #endif // BASE_THREADING_THREAD_LOCAL_STORAGE_H_ | 157 #endif // BASE_THREADING_THREAD_LOCAL_STORAGE_H_ |
OLD | NEW |