1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/ipc/chromium/src/base/thread_local_storage_posix.cc Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,44 @@ 1.4 +// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 1.5 +// Use of this source code is governed by a BSD-style license that can be 1.6 +// found in the LICENSE file. 1.7 + 1.8 +#include "base/thread_local_storage.h" 1.9 + 1.10 +#include "base/logging.h" 1.11 + 1.12 +ThreadLocalStorage::Slot::Slot(TLSDestructorFunc destructor) 1.13 + : initialized_(false) { 1.14 + Initialize(destructor); 1.15 +} 1.16 + 1.17 +bool ThreadLocalStorage::Slot::Initialize(TLSDestructorFunc destructor) { 1.18 + DCHECK(!initialized_); 1.19 + int error = pthread_key_create(&key_, destructor); 1.20 + if (error) { 1.21 + NOTREACHED(); 1.22 + return false; 1.23 + } 1.24 + 1.25 + initialized_ = true; 1.26 + return true; 1.27 +} 1.28 + 1.29 +void ThreadLocalStorage::Slot::Free() { 1.30 + DCHECK(initialized_); 1.31 + int error = pthread_key_delete(key_); 1.32 + if (error) 1.33 + NOTREACHED(); 1.34 + initialized_ = false; 1.35 +} 1.36 + 1.37 +void* ThreadLocalStorage::Slot::Get() const { 1.38 + DCHECK(initialized_); 1.39 + return pthread_getspecific(key_); 1.40 +} 1.41 + 1.42 +void ThreadLocalStorage::Slot::Set(void* value) { 1.43 + DCHECK(initialized_); 1.44 + int error = pthread_setspecific(key_, value); 1.45 + if (error) 1.46 + NOTREACHED(); 1.47 +}