Index: base/threading/thread_local_storage.h |
diff --git a/base/threading/thread_local_storage.h b/base/threading/thread_local_storage.h |
index eb5648f76c9b693a6ac041d5b6a41ee35a1fcad9..5adba4c838f7cd96cd90ea3af50a7b13a427f20c 100644 |
--- a/base/threading/thread_local_storage.h |
+++ b/base/threading/thread_local_storage.h |
@@ -8,12 +8,50 @@ |
#include "base/base_export.h" |
#include "base/basictypes.h" |
-#if defined(OS_POSIX) |
+#if defined(OS_WIN) |
+#include <windows.h> |
+#elif defined(OS_POSIX) |
#include <pthread.h> |
#endif |
namespace base { |
+namespace internal { |
+ |
+// WARNING: You should *NOT* be using this class directly. |
+// PlatformThreadLocalStorage is low-level abstraction to the OS's TLS |
+// interface, you should instead be using ThreadLocalStorage::StaticSlot/Slot, |
+// see thread_local_storage.h. |
+class BASE_EXPORT PlatformThreadLocalStorage { |
+ public: |
+ |
+#if defined(OS_WIN) |
+ typedef unsigned long TLSKey; |
+ enum { TLS_KEY_OUT_OF_INDEXES = TLS_OUT_OF_INDEXES }; |
+#elif defined(OS_POSIX) |
+ typedef pthread_key_t TLSKey; |
+ // In theory, there is no invalid key in Posix, It is critical to define |
+ // one, so we can use minimal system service to implement TLS. |
+ // It is almost imposible to get the defined invalid key, if we do get it, |
+ // just alloc another one. |
jar (doing other things)
2013/11/26 20:05:24
nit: I don't understand the comment. Perhaps you
michaelbai
2013/11/27 00:29:26
Correct, update the comment.
On 2013/11/26 20:05:
|
+ enum { TLS_KEY_OUT_OF_INDEXES = 0x7FFFFFFF }; |
+#endif |
+ // Cross-platform APIs |
jar (doing other things)
2013/11/26 20:05:24
nit: Better comment is:
The following methods nee
michaelbai
2013/11/27 00:29:26
Done.
|
+ static bool AllocTLS(TLSKey* key); |
jar (doing other things)
2013/11/26 20:05:24
You need a comment above line 40 this describing t
michaelbai
2013/11/27 00:29:26
Done.
|
+ static void FreeTLS(TLSKey key); |
jar (doing other things)
2013/11/26 20:05:24
Why do we need to Free our OS slot? Why do we car
michaelbai
2013/11/27 00:29:26
I think it just here for code looks clean.
On 201
|
+ static void SetTLSValue(TLSKey key, void* value); |
+ static void* GetTLSValue(TLSKey key); |
+ |
+ // This is the TLS destructor, the implementation of cross-platform APIs |
jar (doing other things)
2013/11/26 20:05:24
Nit: Delete the phrase "This is the TLS destructor
michaelbai
2013/11/27 00:29:26
Done.
|
+ // should call this method on the terminating thread when a thread exits, |
+ // this function calls any TLS destructors that were passed in from |
+ // ThreadLocalStorage::StaticSlot::Initialize() and are pending for the |
+ // thread. |
+ static void OnThreadExit(); |
+}; |
+ |
+} // namespace internal |
+ |
// Wrapper for thread local storage. This class doesn't do much except provide |
// an API for portability. |
class BASE_EXPORT ThreadLocalStorage { |
@@ -60,12 +98,7 @@ class BASE_EXPORT ThreadLocalStorage { |
// The internals of this struct should be considered private. |
bool initialized_; |
-#if defined(OS_WIN) |
int slot_; |
-#elif defined(OS_POSIX) |
- pthread_key_t key_; |
-#endif |
- |
}; |
// A convenience wrapper around StaticSlot with a constructor. Can be used |
@@ -77,11 +110,8 @@ class BASE_EXPORT ThreadLocalStorage { |
private: |
using StaticSlot::initialized_; |
-#if defined(OS_WIN) |
using StaticSlot::slot_; |
-#elif defined(OS_POSIX) |
- using StaticSlot::key_; |
-#endif |
+ |
DISALLOW_COPY_AND_ASSIGN(Slot); |
}; |