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 #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 #pragma once | 7 #pragma once |
8 | 8 |
9 #include "base/base_api.h" | 9 #include "base/base_export.h" |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
11 | 11 |
12 #if defined(OS_POSIX) | 12 #if defined(OS_POSIX) |
13 #include <pthread.h> | 13 #include <pthread.h> |
14 #endif | 14 #endif |
15 | 15 |
16 namespace base { | 16 namespace base { |
17 | 17 |
18 // Wrapper for thread local storage. This class doesn't do much except provide | 18 // Wrapper for thread local storage. This class doesn't do much except provide |
19 // an API for portability. | 19 // an API for portability. |
20 class BASE_API ThreadLocalStorage { | 20 class BASE_EXPORT ThreadLocalStorage { |
21 public: | 21 public: |
22 | 22 |
23 // Prototype for the TLS destructor function, which can be optionally used to | 23 // Prototype for the TLS destructor function, which can be optionally used to |
24 // cleanup thread local storage on thread exit. 'value' is the data that is | 24 // cleanup thread local storage on thread exit. 'value' is the data that is |
25 // stored in thread local storage. | 25 // stored in thread local storage. |
26 typedef void (*TLSDestructorFunc)(void* value); | 26 typedef void (*TLSDestructorFunc)(void* value); |
27 | 27 |
28 // A key representing one value stored in TLS. | 28 // A key representing one value stored in TLS. |
29 class BASE_API Slot { | 29 class BASE_EXPORT Slot { |
30 public: | 30 public: |
31 explicit Slot(TLSDestructorFunc destructor = NULL); | 31 explicit Slot(TLSDestructorFunc destructor = NULL); |
32 | 32 |
33 // This constructor should be used for statics. | 33 // This constructor should be used for statics. |
34 // It returns an uninitialized Slot. | 34 // It returns an uninitialized Slot. |
35 explicit Slot(base::LinkerInitialized x) {} | 35 explicit Slot(base::LinkerInitialized x) {} |
36 | 36 |
37 // Set up the TLS slot. Called by the constructor. | 37 // Set up the TLS slot. Called by the constructor. |
38 // 'destructor' is a pointer to a function to perform per-thread cleanup of | 38 // 'destructor' is a pointer to a function to perform per-thread cleanup of |
39 // this object. If set to NULL, no cleanup is done for this TLS slot. | 39 // this object. If set to NULL, no cleanup is done for this TLS slot. |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
87 static long tls_max_; | 87 static long tls_max_; |
88 static TLSDestructorFunc tls_destructors_[kThreadLocalStorageSize]; | 88 static TLSDestructorFunc tls_destructors_[kThreadLocalStorageSize]; |
89 #endif // OS_WIN | 89 #endif // OS_WIN |
90 | 90 |
91 DISALLOW_COPY_AND_ASSIGN(ThreadLocalStorage); | 91 DISALLOW_COPY_AND_ASSIGN(ThreadLocalStorage); |
92 }; | 92 }; |
93 | 93 |
94 } // namespace base | 94 } // namespace base |
95 | 95 |
96 #endif // BASE_THREADING_THREAD_LOCAL_STORAGE_H_ | 96 #endif // BASE_THREADING_THREAD_LOCAL_STORAGE_H_ |
OLD | NEW |