thread_local_storage_posix.cc 853 Bytes
Newer Older
gejun's avatar
gejun committed
1 2 3 4
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

5
#include "butil/threading/thread_local_storage.h"
gejun's avatar
gejun committed
6

7
#include "butil/logging.h"
gejun's avatar
gejun committed
8

9
namespace butil {
gejun's avatar
gejun committed
10 11 12 13 14

namespace internal {

bool PlatformThreadLocalStorage::AllocTLS(TLSKey* key) {
  return !pthread_key_create(key,
15
      butil::internal::PlatformThreadLocalStorage::OnThreadExit);
gejun's avatar
gejun committed
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
}

void PlatformThreadLocalStorage::FreeTLS(TLSKey key) {
  int ret = pthread_key_delete(key);
  DCHECK_EQ(ret, 0);
}

void* PlatformThreadLocalStorage::GetTLSValue(TLSKey key) {
  return pthread_getspecific(key);
}

void PlatformThreadLocalStorage::SetTLSValue(TLSKey key, void* value) {
  int ret = pthread_setspecific(key, value);
  DCHECK_EQ(ret, 0);
}

}  // namespace internal

34
}  // namespace butil