diff options
author | evanm@google.com <evanm@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-08-20 21:47:40 +0000 |
---|---|---|
committer | evanm@google.com <evanm@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-08-20 21:47:40 +0000 |
commit | c3ec35638ea6594b6bdbac7ff92c38add8984623 (patch) | |
tree | c51541ac2451e66c410b3d244e1f59ac2218c57e /base/thread_local_storage_posix.cc | |
parent | e537c3515e270527ba2fa54fcfc4a1ed49cc975e (diff) | |
download | chromium_src-c3ec35638ea6594b6bdbac7ff92c38add8984623.zip chromium_src-c3ec35638ea6594b6bdbac7ff92c38add8984623.tar.gz chromium_src-c3ec35638ea6594b6bdbac7ff92c38add8984623.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@1113 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/thread_local_storage_posix.cc')
-rw-r--r-- | base/thread_local_storage_posix.cc | 38 |
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(); } |