LCOV - code coverage report
Current view: top level - lib/Support/Unix - ThreadLocal.inc (source / functions) Hit Total Coverage
Test: llvm-toolchain.info Lines: 17 19 89.5 %
Date: 2018-10-20 13:21:21 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             : #include "llvm/Config/config.h"
      20             : 
      21             : #if defined(HAVE_PTHREAD_H) && defined(HAVE_PTHREAD_GETSPECIFIC)
      22             : 
      23             : #include <cassert>
      24             : #include <pthread.h>
      25             : #include <stdlib.h>
      26             : 
      27             : namespace llvm {
      28             : using namespace sys;
      29             : 
      30       23472 : ThreadLocalImpl::ThreadLocalImpl() : data() {
      31             :   static_assert(sizeof(pthread_key_t) <= sizeof(data), "size too big");
      32             :   pthread_key_t* key = reinterpret_cast<pthread_key_t*>(&data);
      33        2608 :   int errorcode = pthread_key_create(key, nullptr);
      34             :   assert(errorcode == 0);
      35             :   (void) errorcode;
      36        2608 : }
      37             : 
      38        1230 : ThreadLocalImpl::~ThreadLocalImpl() {
      39             :   pthread_key_t* key = reinterpret_cast<pthread_key_t*>(&data);
      40         615 :   int errorcode = pthread_key_delete(*key);
      41             :   assert(errorcode == 0);
      42             :   (void) errorcode;
      43         615 : }
      44           0 : 
      45             : void ThreadLocalImpl::setInstance(const void* d) {
      46             :   pthread_key_t* key = reinterpret_cast<pthread_key_t*>(&data);
      47             :   int errorcode = pthread_setspecific(*key, d);
      48             :   assert(errorcode == 0);
      49           0 :   (void) errorcode;
      50        1230 : }
      51             : 
      52         615 : void *ThreadLocalImpl::getInstance() {
      53             :   pthread_key_t* key = reinterpret_cast<pthread_key_t*>(&data);
      54             :   return pthread_getspecific(*key);
      55         615 : }
      56             : 
      57       10203 : void ThreadLocalImpl::removeInstance() {
      58             :   setInstance(nullptr);
      59       10203 : }
      60             : 
      61             : }
      62       10203 : #else
      63             : namespace llvm {
      64       18159 : using namespace sys;
      65             : ThreadLocalImpl::ThreadLocalImpl() : data() { }
      66       18159 : ThreadLocalImpl::~ThreadLocalImpl() { }
      67             : void ThreadLocalImpl::setInstance(const void* d) { data = const_cast<void*>(d);}
      68             : void *ThreadLocalImpl::getInstance() { return data; }
      69           2 : void ThreadLocalImpl::removeInstance() { setInstance(0); }
      70           2 : }
      71           2 : #endif

Generated by: LCOV version 1.13