| OLD | NEW |
| 1 // Copyright (c) 2006-2008 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/basictypes.h" | 10 #include "base/basictypes.h" |
| 10 | 11 |
| 11 #if defined(OS_POSIX) | 12 #if defined(OS_POSIX) |
| 12 #include <pthread.h> | 13 #include <pthread.h> |
| 13 #endif | 14 #endif |
| 14 | 15 |
| 15 namespace base { | 16 namespace base { |
| 16 | 17 |
| 17 // 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 |
| 18 // an API for portability. | 19 // an API for portability. |
| 19 class ThreadLocalStorage { | 20 class BASE_API ThreadLocalStorage { |
| 20 public: | 21 public: |
| 21 | 22 |
| 22 // 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 |
| 23 // 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 |
| 24 // stored in thread local storage. | 25 // stored in thread local storage. |
| 25 typedef void (*TLSDestructorFunc)(void* value); | 26 typedef void (*TLSDestructorFunc)(void* value); |
| 26 | 27 |
| 27 // A key representing one value stored in TLS. | 28 // A key representing one value stored in TLS. |
| 28 class Slot { | 29 class BASE_API Slot { |
| 29 public: | 30 public: |
| 30 explicit Slot(TLSDestructorFunc destructor = NULL); | 31 explicit Slot(TLSDestructorFunc destructor = NULL); |
| 31 | 32 |
| 32 // This constructor should be used for statics. | 33 // This constructor should be used for statics. |
| 33 // It returns an uninitialized Slot. | 34 // It returns an uninitialized Slot. |
| 34 explicit Slot(base::LinkerInitialized x) {} | 35 explicit Slot(base::LinkerInitialized x) {} |
| 35 | 36 |
| 36 // Set up the TLS slot. Called by the constructor. | 37 // Set up the TLS slot. Called by the constructor. |
| 37 // '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 |
| 38 // 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... |
| 86 static long tls_max_; | 87 static long tls_max_; |
| 87 static TLSDestructorFunc tls_destructors_[kThreadLocalStorageSize]; | 88 static TLSDestructorFunc tls_destructors_[kThreadLocalStorageSize]; |
| 88 #endif // OS_WIN | 89 #endif // OS_WIN |
| 89 | 90 |
| 90 DISALLOW_COPY_AND_ASSIGN(ThreadLocalStorage); | 91 DISALLOW_COPY_AND_ASSIGN(ThreadLocalStorage); |
| 91 }; | 92 }; |
| 92 | 93 |
| 93 } // namespace base | 94 } // namespace base |
| 94 | 95 |
| 95 #endif // BASE_THREADING_THREAD_LOCAL_STORAGE_H_ | 96 #endif // BASE_THREADING_THREAD_LOCAL_STORAGE_H_ |
| OLD | NEW |