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 // WARNING: Thread local storage is a bit tricky to get right. Please make | 5 // WARNING: Thread local storage is a bit tricky to get right. Please make |
6 // sure that this is really the proper solution for what you're trying to | 6 // sure that this is really the proper solution for what you're trying to |
7 // achieve. Don't prematurely optimize, most likely you can just use a Lock. | 7 // achieve. Don't prematurely optimize, most likely you can just use a Lock. |
8 // | 8 // |
9 // These classes implement a wrapper around the platform's TLS storage | 9 // These classes implement a wrapper around the platform's TLS storage |
10 // mechanism. On construction, they will allocate a TLS slot, and free the | 10 // mechanism. On construction, they will allocate a TLS slot, and free the |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
107 class ThreadLocalBoolean { | 107 class ThreadLocalBoolean { |
108 public: | 108 public: |
109 ThreadLocalBoolean() { } | 109 ThreadLocalBoolean() { } |
110 ~ThreadLocalBoolean() { } | 110 ~ThreadLocalBoolean() { } |
111 | 111 |
112 bool Get() { | 112 bool Get() { |
113 return tlp_.Get() != NULL; | 113 return tlp_.Get() != NULL; |
114 } | 114 } |
115 | 115 |
116 void Set(bool val) { | 116 void Set(bool val) { |
117 tlp_.Set(reinterpret_cast<void*>(val ? 1 : 0)); | 117 tlp_.Set(val ? this : NULL); |
118 } | 118 } |
119 | 119 |
120 private: | 120 private: |
121 ThreadLocalPointer<void> tlp_; | 121 ThreadLocalPointer<void> tlp_; |
122 | 122 |
123 DISALLOW_COPY_AND_ASSIGN(ThreadLocalBoolean); | 123 DISALLOW_COPY_AND_ASSIGN(ThreadLocalBoolean); |
124 }; | 124 }; |
125 | 125 |
126 } // namespace base | 126 } // namespace base |
127 | 127 |
128 #endif // BASE_THREADING_THREAD_LOCAL_H_ | 128 #endif // BASE_THREADING_THREAD_LOCAL_H_ |
OLD | NEW |