1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "base/threading/thread_local_storage.h"
7 #include "base/logging.h"
11 ThreadLocalStorage::Slot::Slot(TLSDestructorFunc destructor) {
14 Initialize(destructor);
17 bool ThreadLocalStorage::StaticSlot::Initialize(TLSDestructorFunc destructor) {
18 DCHECK(!initialized_);
19 int error = pthread_key_create(&key_, destructor);
29 void ThreadLocalStorage::StaticSlot::Free() {
31 int error = pthread_key_delete(key_);
37 void* ThreadLocalStorage::StaticSlot::Get() const {
39 return pthread_getspecific(key_);
42 void ThreadLocalStorage::StaticSlot::Set(void* value) {
44 int error = pthread_setspecific(key_, value);