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> | 8 #include <stdint.h> |
9 | 9 |
10 #include "base/atomicops.h" | 10 #include "base/atomicops.h" |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
49 // that to support a much larger number of Chromium slots (independent of the | 49 // that to support a much larger number of Chromium slots (independent of the |
50 // OS restrictions). | 50 // OS restrictions). |
51 // The following returns true if it successfully is able to return an OS | 51 // The following returns true if it successfully is able to return an OS |
52 // key in |key|. | 52 // key in |key|. |
53 static bool AllocTLS(TLSKey* key); | 53 static bool AllocTLS(TLSKey* key); |
54 // Note: FreeTLS() doesn't have to be called, it is fine with this leak, OS | 54 // Note: FreeTLS() doesn't have to be called, it is fine with this leak, OS |
55 // might not reuse released slot, you might just reset the TLS value with | 55 // might not reuse released slot, you might just reset the TLS value with |
56 // SetTLSValue(). | 56 // SetTLSValue(). |
57 static void FreeTLS(TLSKey key); | 57 static void FreeTLS(TLSKey key); |
58 static void SetTLSValue(TLSKey key, void* value); | 58 static void SetTLSValue(TLSKey key, void* value); |
59 static void* GetTLSValue(TLSKey key); | 59 static void* GetTLSValue(TLSKey key) { |
| 60 #if defined(OS_WIN) |
| 61 return TlsGetValue(key); |
| 62 #elif defined(OS_POSIX) |
| 63 return pthread_getspecific(key); |
| 64 #endif |
| 65 } |
60 | 66 |
61 // Each platform (OS implementation) is required to call this method on each | 67 // Each platform (OS implementation) is required to call this method on each |
62 // terminating thread when the thread is about to terminate. This method | 68 // terminating thread when the thread is about to terminate. This method |
63 // will then call all registered destructors for slots in Chromium | 69 // will then call all registered destructors for slots in Chromium |
64 // ThreadLocalStorage, until there are no slot values remaining as having | 70 // ThreadLocalStorage, until there are no slot values remaining as having |
65 // been set on this thread. | 71 // been set on this thread. |
66 // Destructors may end up being called multiple times on a terminating | 72 // Destructors may end up being called multiple times on a terminating |
67 // thread, as other destructors may re-set slots that were previously | 73 // thread, as other destructors may re-set slots that were previously |
68 // destroyed. | 74 // destroyed. |
69 #if defined(OS_WIN) | 75 #if defined(OS_WIN) |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
151 DISALLOW_COPY_AND_ASSIGN(Slot); | 157 DISALLOW_COPY_AND_ASSIGN(Slot); |
152 }; | 158 }; |
153 | 159 |
154 private: | 160 private: |
155 DISALLOW_COPY_AND_ASSIGN(ThreadLocalStorage); | 161 DISALLOW_COPY_AND_ASSIGN(ThreadLocalStorage); |
156 }; | 162 }; |
157 | 163 |
158 } // namespace base | 164 } // namespace base |
159 | 165 |
160 #endif // BASE_THREADING_THREAD_LOCAL_STORAGE_H_ | 166 #endif // BASE_THREADING_THREAD_LOCAL_STORAGE_H_ |
OLD | NEW |