summaryrefslogtreecommitdiffstats
path: root/base/thread_local_storage_posix.cc
diff options
context:
space:
mode:
authorevanm@google.com <evanm@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2008-08-20 22:54:52 +0000
committerevanm@google.com <evanm@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2008-08-20 22:54:52 +0000
commit6a6e657234868ad4044b03bdeb9c6f7e872b5ee6 (patch)
tree36d9855863e1cf5615b62623b2347ec494447cdb /base/thread_local_storage_posix.cc
parent15e8abe105f4c2a08cd5dc51e95ec1791ac440f2 (diff)
downloadchromium_src-6a6e657234868ad4044b03bdeb9c6f7e872b5ee6.zip
chromium_src-6a6e657234868ad4044b03bdeb9c6f7e872b5ee6.tar.gz
chromium_src-6a6e657234868ad4044b03bdeb9c6f7e872b5ee6.tar.bz2
TrackedObjects assumes you can use a "TLS slot" of -1 to indicate uninitialized. This isn't true for the pthread_key_t type, which is unsigned on Linux and reportedly a struct on Macs. This change modifies the Slot type to be a struct containing an "initialized" flag.
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@1122 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/thread_local_storage_posix.cc')
-rw-r--r--base/thread_local_storage_posix.cc38
1 files changed, 27 insertions, 11 deletions
diff --git a/base/thread_local_storage_posix.cc b/base/thread_local_storage_posix.cc
index bcc982f..7c24e59 100644
--- a/base/thread_local_storage_posix.cc
+++ b/base/thread_local_storage_posix.cc
@@ -31,23 +31,39 @@
#include "base/logging.h"
-TLSSlot ThreadLocalStorage::Alloc(TLSDestructorFunc destructor) {
- TLSSlot key;
- int error = pthread_key_create(&key, destructor);
- if (error)
+ThreadLocalStorage::Slot::Slot(TLSDestructorFunc destructor)
+ : initialized_(false) {
+ Initialize(destructor);
+}
+
+bool ThreadLocalStorage::Slot::Initialize(TLSDestructorFunc destructor) {
+ DCHECK(!initialized_);
+ int error = pthread_key_create(&key_, destructor);
+ if (error) {
NOTREACHED();
+ return false;
+ }
- return key;
+ initialized_ = true;
+ return true;
}
-void ThreadLocalStorage::Free(TLSSlot slot) {
- pthread_key_delete(slot);
+void ThreadLocalStorage::Slot::Free() {
+ DCHECK(initialized_);
+ int error = pthread_key_delete(key_);
+ if (error)
+ NOTREACHED();
+ initialized_ = false;
}
-void* ThreadLocalStorage::Get(TLSSlot slot) {
- return pthread_getspecific(slot);
+void* ThreadLocalStorage::Slot::Get() const {
+ DCHECK(initialized_);
+ return pthread_getspecific(key_);
}
-void ThreadLocalStorage::Set(TLSSlot slot, void* value) {
- pthread_setspecific(slot, value);
+void ThreadLocalStorage::Slot::Set(void* value) {
+ DCHECK(initialized_);
+ int error = pthread_setspecific(key_, value);
+ if (error)
+ NOTREACHED();
}