thread_local_storage_posix.cc 751 B

123456789101112131415161718192021222324252627282930
  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.
  4. #include "base/threading/thread_local_storage.h"
  5. #include "base/check_op.h"
  6. namespace base {
  7. namespace internal {
  8. bool PlatformThreadLocalStorage::AllocTLS(TLSKey* key) {
  9. return !pthread_key_create(key,
  10. base::internal::PlatformThreadLocalStorage::OnThreadExit);
  11. }
  12. void PlatformThreadLocalStorage::FreeTLS(TLSKey key) {
  13. int ret = pthread_key_delete(key);
  14. DCHECK_EQ(ret, 0);
  15. }
  16. void PlatformThreadLocalStorage::SetTLSValue(TLSKey key, void* value) {
  17. int ret = pthread_setspecific(key, value);
  18. DCHECK_EQ(ret, 0);
  19. }
  20. } // namespace internal
  21. } // namespace base