It turns out most of the thumb2 instructions are not allowed to touch SP. The semanti...
[llvm/avr.git] / lib / System / ThreadLocal.cpp
blobe7054b528147189d2f02fde53de63aa793e48fd2
1 //===- ThreadLocal.cpp - 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 llvm::sys::ThreadLocal class.
12 //===----------------------------------------------------------------------===//
14 #include "llvm/Config/config.h"
15 #include "llvm/System/ThreadLocal.h"
17 //===----------------------------------------------------------------------===//
18 //=== WARNING: Implementation here must contain only TRULY operating system
19 //=== independent code.
20 //===----------------------------------------------------------------------===//
22 #if !defined(ENABLE_THREADS) || ENABLE_THREADS == 0
23 // Define all methods as no-ops if threading is explicitly disabled
24 namespace llvm {
25 using namespace sys;
26 ThreadLocalImpl::ThreadLocalImpl() { }
27 ThreadLocalImpl::~ThreadLocalImpl() { }
28 void ThreadLocalImpl::setInstance(const void* d) { data = const_cast<void*>(d);}
29 const void* ThreadLocalImpl::getInstance() { return data; }
31 #else
33 #if defined(HAVE_PTHREAD_H) && defined(HAVE_PTHREAD_GETSPECIFIC)
35 #include <cassert>
36 #include <pthread.h>
37 #include <stdlib.h>
39 namespace llvm {
40 using namespace sys;
42 ThreadLocalImpl::ThreadLocalImpl() : data(0) {
43 pthread_key_t* key = new pthread_key_t;
44 int errorcode = pthread_key_create(key, NULL);
45 assert(errorcode == 0);
46 (void) errorcode;
47 data = (void*)key;
50 ThreadLocalImpl::~ThreadLocalImpl() {
51 pthread_key_t* key = static_cast<pthread_key_t*>(data);
52 int errorcode = pthread_key_delete(*key);
53 assert(errorcode == 0);
54 (void) errorcode;
55 delete key;
58 void ThreadLocalImpl::setInstance(const void* d) {
59 pthread_key_t* key = static_cast<pthread_key_t*>(data);
60 int errorcode = pthread_setspecific(*key, d);
61 assert(errorcode == 0);
62 (void) errorcode;
65 const void* ThreadLocalImpl::getInstance() {
66 pthread_key_t* key = static_cast<pthread_key_t*>(data);
67 return pthread_getspecific(*key);
72 #elif defined(LLVM_ON_UNIX)
73 #include "Unix/ThreadLocal.inc"
74 #elif defined( LLVM_ON_WIN32)
75 #include "Win32/ThreadLocal.inc"
76 #else
77 #warning Neither LLVM_ON_UNIX nor LLVM_ON_WIN32 was set in System/ThreadLocal.cpp
78 #endif
79 #endif