summaryrefslogtreecommitdiffstats
path: root/base/thread_local_storage_win.cc
diff options
context:
space:
mode:
authorevanm@google.com <evanm@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2008-08-20 22:11:47 +0000
committerevanm@google.com <evanm@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2008-08-20 22:11:47 +0000
commitfa87a2527ca8c0bcef92d8e44791332782936911 (patch)
tree04dc5d1e6881f8356f91203a386648057b20d924 /base/thread_local_storage_win.cc
parent4f64d0af5908e36d356c834005d08cca98d579fe (diff)
downloadchromium_src-fa87a2527ca8c0bcef92d8e44791332782936911.zip
chromium_src-fa87a2527ca8c0bcef92d8e44791332782936911.tar.gz
chromium_src-fa87a2527ca8c0bcef92d8e44791332782936911.tar.bz2
Revert. Failing unit tests.
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@1118 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/thread_local_storage_win.cc')
-rw-r--r--base/thread_local_storage_win.cc53
1 files changed, 23 insertions, 30 deletions
diff --git a/base/thread_local_storage_win.cc b/base/thread_local_storage_win.cc
index 154935a..8157e88 100644
--- a/base/thread_local_storage_win.cc
+++ b/base/thread_local_storage_win.cc
@@ -55,7 +55,7 @@ long ThreadLocalStorage::tls_max_ = 1;
ThreadLocalStorage::TLSDestructorFunc
ThreadLocalStorage::tls_destructors_[kThreadLocalStorageSize];
-void** ThreadLocalStorage::Initialize() {
+void **ThreadLocalStorage::Initialize() {
if (tls_key_ == TLS_OUT_OF_INDEXES) {
long value = TlsAlloc();
DCHECK(value != TLS_OUT_OF_INDEXES);
@@ -73,59 +73,52 @@ void** ThreadLocalStorage::Initialize() {
DCHECK(TlsGetValue(tls_key_) == NULL);
// Create an array to store our data.
- void** tls_data = new void*[kThreadLocalStorageSize];
+ void **tls_data = new void*[kThreadLocalStorageSize];
memset(tls_data, 0, sizeof(void*[kThreadLocalStorageSize]));
TlsSetValue(tls_key_, tls_data);
return tls_data;
}
-ThreadLocalStorage::Slot::Slot(TLSDestructorFunc destructor)
- : initialized_(false) {
- Initialize(destructor);
-}
-
-bool ThreadLocalStorage::Slot::Initialize(TLSDestructorFunc destructor) {
+TLSSlot ThreadLocalStorage::Alloc(TLSDestructorFunc destructor) {
if (tls_key_ == TLS_OUT_OF_INDEXES || !TlsGetValue(tls_key_))
- ThreadLocalStorage::Initialize();
+ Initialize();
// Grab a new slot.
- slot_ = InterlockedIncrement(&tls_max_) - 1;
- if (slot_ >= kThreadLocalStorageSize) {
+ int slot = InterlockedIncrement(&tls_max_) - 1;
+ if (slot >= kThreadLocalStorageSize) {
NOTREACHED();
- return false;
+ return -1;
}
// Setup our destructor.
- tls_destructors_[slot_] = destructor;
- initialized_ = true;
- return true;
+ tls_destructors_[slot] = destructor;
+ return slot;
}
-void ThreadLocalStorage::Slot::Free() {
+void ThreadLocalStorage::Free(TLSSlot slot) {
// At this time, we don't reclaim old indices for TLS slots.
// So all we need to do is wipe the destructor.
- tls_destructors_[slot_] = NULL;
- initialized_ = false;
+ tls_destructors_[slot] = NULL;
}
-void* ThreadLocalStorage::Slot::Get() const {
- void** tls_data = static_cast<void**>(TlsGetValue(tls_key_));
+void* ThreadLocalStorage::Get(TLSSlot slot) {
+ void **tls_data = static_cast<void**>(TlsGetValue(tls_key_));
if (!tls_data)
- tls_data = ThreadLocalStorage::Initialize();
- DCHECK(slot_ >= 0 && slot_ < kThreadLocalStorageSize);
- return tls_data[slot_];
+ tls_data = Initialize();
+ DCHECK(slot >= 0 && slot < kThreadLocalStorageSize);
+ return tls_data[slot];
}
-void ThreadLocalStorage::Slot::Set(void* value) {
- void** tls_data = static_cast<void**>(TlsGetValue(tls_key_));
+void ThreadLocalStorage::Set(TLSSlot slot, void* value) {
+ void **tls_data = static_cast<void**>(TlsGetValue(tls_key_));
if (!tls_data)
- tls_data = ThreadLocalStorage::Initialize();
- DCHECK(slot_ >= 0 && slot_ < kThreadLocalStorageSize);
- tls_data[slot_] = value;
+ tls_data = Initialize();
+ DCHECK(slot >= 0 && slot < kThreadLocalStorageSize);
+ tls_data[slot] = value;
}
void ThreadLocalStorage::ThreadExit() {
- void** tls_data = static_cast<void**>(TlsGetValue(tls_key_));
+ void **tls_data = static_cast<void**>(TlsGetValue(tls_key_));
// Maybe we have never initialized TLS for this thread.
if (!tls_data)
@@ -133,7 +126,7 @@ void ThreadLocalStorage::ThreadExit() {
for (int slot = 0; slot < tls_max_; slot++) {
if (tls_destructors_[slot] != NULL) {
- void* value = tls_data[slot];
+ void *value = tls_data[slot];
tls_destructors_[slot](value);
}
}