Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2)

Unified Diff: trunk/src/base/threading/thread_local.h

Issue 184273006: Revert 254986 "Switch thread_local to use chromium's TLS impleme..." (Closed) Base URL: svn://svn.chromium.org/chrome/
Patch Set: Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « trunk/src/base/base.gypi ('k') | trunk/src/base/threading/thread_local_posix.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: trunk/src/base/threading/thread_local.h
===================================================================
--- trunk/src/base/threading/thread_local.h (revision 255100)
+++ trunk/src/base/threading/thread_local.h (working copy)
@@ -50,28 +50,56 @@
#include "base/base_export.h"
#include "base/basictypes.h"
-#include "base/threading/thread_local_storage.h"
+#if defined(OS_POSIX)
+#include <pthread.h>
+#endif
+
namespace base {
+namespace internal {
+// Helper functions that abstract the cross-platform APIs. Do not use directly.
+struct BASE_EXPORT ThreadLocalPlatform {
+#if defined(OS_WIN)
+ typedef unsigned long SlotType;
+#elif defined(OS_POSIX)
+ typedef pthread_key_t SlotType;
+#endif
+
+ static void AllocateSlot(SlotType* slot);
+ static void FreeSlot(SlotType slot);
+ static void* GetValueFromSlot(SlotType slot);
+ static void SetValueInSlot(SlotType slot, void* value);
+};
+
+} // namespace internal
+
template <typename Type>
class ThreadLocalPointer {
public:
- ThreadLocalPointer() {}
+ ThreadLocalPointer() : slot_() {
+ internal::ThreadLocalPlatform::AllocateSlot(&slot_);
+ }
- ~ThreadLocalPointer() {}
+ ~ThreadLocalPointer() {
+ internal::ThreadLocalPlatform::FreeSlot(slot_);
+ }
Type* Get() {
- return static_cast<Type*>(slot_.Get());
+ return static_cast<Type*>(
+ internal::ThreadLocalPlatform::GetValueFromSlot(slot_));
}
void Set(Type* ptr) {
- slot_.Set(const_cast<void*>(static_cast<const void*>(ptr)));
+ internal::ThreadLocalPlatform::SetValueInSlot(
+ slot_, const_cast<void*>(static_cast<const void*>(ptr)));
}
private:
- ThreadLocalStorage::Slot slot_;
+ typedef internal::ThreadLocalPlatform::SlotType SlotType;
+ SlotType slot_;
+
DISALLOW_COPY_AND_ASSIGN(ThreadLocalPointer<Type>);
};
« no previous file with comments | « trunk/src/base/base.gypi ('k') | trunk/src/base/threading/thread_local_posix.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698