ipc/chromium/src/base/thread_local_storage_posix.cc

Fri, 16 Jan 2015 04:50:19 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Fri, 16 Jan 2015 04:50:19 +0100
branch
TOR_BUG_9701
changeset 13
44a2da4a2ab2
permissions
-rw-r--r--

Replace accessor implementation with direct member state manipulation, by
request https://trac.torproject.org/projects/tor/ticket/9701#comment:32

     1 // Copyright (c) 2006-2008 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/thread_local_storage.h"
     7 #include "base/logging.h"
     9 ThreadLocalStorage::Slot::Slot(TLSDestructorFunc destructor)
    10     : initialized_(false) {
    11   Initialize(destructor);
    12 }
    14 bool ThreadLocalStorage::Slot::Initialize(TLSDestructorFunc destructor) {
    15   DCHECK(!initialized_);
    16   int error = pthread_key_create(&key_, destructor);
    17   if (error) {
    18     NOTREACHED();
    19     return false;
    20   }
    22   initialized_ = true;
    23   return true;
    24 }
    26 void ThreadLocalStorage::Slot::Free() {
    27   DCHECK(initialized_);
    28   int error = pthread_key_delete(key_);
    29   if (error)
    30     NOTREACHED();
    31   initialized_ = false;
    32 }
    34 void* ThreadLocalStorage::Slot::Get() const {
    35   DCHECK(initialized_);
    36   return pthread_getspecific(key_);
    37 }
    39 void ThreadLocalStorage::Slot::Set(void* value) {
    40   DCHECK(initialized_);
    41   int error = pthread_setspecific(key_, value);
    42   if (error)
    43     NOTREACHED();
    44 }

mercurial