LCOV - code coverage report
Current view: top level - lib/Support/Unix - ThreadLocal.inc (source / functions) Hit Total Coverage
Test: llvm-toolchain.info Lines: 18 18 100.0 %
Date: 2017-09-14 15:23:50 Functions: 5 6 83.3 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : //=== llvm/Support/Unix/ThreadLocal.inc - Unix Thread Local Data -*- C++ -*-===//
       2             : //
       3             : //                     The LLVM Compiler Infrastructure
       4             : //
       5             : // This file is distributed under the University of Illinois Open Source
       6             : // License. See LICENSE.TXT for details.
       7             : //
       8             : //===----------------------------------------------------------------------===//
       9             : //
      10             : // This file implements the Unix specific (non-pthread) ThreadLocal class.
      11             : //
      12             : //===----------------------------------------------------------------------===//
      13             : 
      14             : //===----------------------------------------------------------------------===//
      15             : //=== WARNING: Implementation here must contain only generic UNIX code that
      16             : //===          is guaranteed to work on *all* UNIX variants.
      17             : //===----------------------------------------------------------------------===//
      18             : 
      19             : #if defined(HAVE_PTHREAD_H) && defined(HAVE_PTHREAD_GETSPECIFIC)
      20             : 
      21             : #include <cassert>
      22             : #include <pthread.h>
      23             : #include <stdlib.h>
      24             : 
      25             : namespace llvm {
      26             : using namespace sys;
      27             : 
      28        2402 : ThreadLocalImpl::ThreadLocalImpl() : data() {
      29             :   static_assert(sizeof(pthread_key_t) <= sizeof(data), "size too big");
      30        2402 :   pthread_key_t* key = reinterpret_cast<pthread_key_t*>(&data);
      31        2402 :   int errorcode = pthread_key_create(key, nullptr);
      32             :   assert(errorcode == 0);
      33             :   (void) errorcode;
      34        2402 : }
      35             : 
      36        1092 : ThreadLocalImpl::~ThreadLocalImpl() {
      37         546 :   pthread_key_t* key = reinterpret_cast<pthread_key_t*>(&data);
      38         546 :   int errorcode = pthread_key_delete(*key);
      39             :   assert(errorcode == 0);
      40             :   (void) errorcode;
      41         546 : }
      42             : 
      43        9429 : void ThreadLocalImpl::setInstance(const void* d) {
      44        9429 :   pthread_key_t* key = reinterpret_cast<pthread_key_t*>(&data);
      45        9429 :   int errorcode = pthread_setspecific(*key, d);
      46             :   assert(errorcode == 0);
      47             :   (void) errorcode;
      48        9429 : }
      49             : 
      50       16948 : void *ThreadLocalImpl::getInstance() {
      51       16948 :   pthread_key_t* key = reinterpret_cast<pthread_key_t*>(&data);
      52       16948 :   return pthread_getspecific(*key);
      53             : }
      54             : 
      55           2 : void ThreadLocalImpl::removeInstance() {
      56           2 :   setInstance(nullptr);
      57           2 : }
      58             : 
      59             : }
      60             : #else
      61             : namespace llvm {
      62             : using namespace sys;
      63             : ThreadLocalImpl::ThreadLocalImpl() : data() { }
      64             : ThreadLocalImpl::~ThreadLocalImpl() { }
      65             : void ThreadLocalImpl::setInstance(const void* d) { data = const_cast<void*>(d);}
      66             : void *ThreadLocalImpl::getInstance() { return data; }
      67             : void ThreadLocalImpl::removeInstance() { setInstance(0); }
      68             : }
      69             : #endif

Generated by: LCOV version 1.13