LLVM  14.0.0git
ThreadLocal.h
Go to the documentation of this file.
1 //===- llvm/Support/ThreadLocal.h - Thread Local Data ------------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file declares the llvm::sys::ThreadLocal class.
10 //
11 //===----------------------------------------------------------------------===//
12 
13 #ifndef LLVM_SUPPORT_THREADLOCAL_H
14 #define LLVM_SUPPORT_THREADLOCAL_H
15 
16 #include "llvm/Support/DataTypes.h"
17 #include "llvm/Support/Threading.h"
18 #include <cassert>
19 
20 namespace llvm {
21  namespace sys {
22  // ThreadLocalImpl - Common base class of all ThreadLocal instantiations.
23  // YOU SHOULD NEVER USE THIS DIRECTLY.
26  /// Platform-specific thread local data.
27  ///
28  /// This is embedded in the class and we avoid malloc'ing/free'ing it,
29  /// to make this class more safe for use along with CrashRecoveryContext.
30  union {
31  char data[sizeof(ThreadLocalDataTy)];
33  };
34  public:
36  virtual ~ThreadLocalImpl();
37  void setInstance(const void* d);
38  void *getInstance();
39  void removeInstance();
40  };
41 
42  /// ThreadLocal - A class used to abstract thread-local storage. It holds,
43  /// for each thread, a pointer a single object of type T.
44  template<class T>
45  class ThreadLocal : public ThreadLocalImpl {
46  public:
48 
49  /// get - Fetches a pointer to the object associated with the current
50  /// thread. If no object has yet been associated, it returns NULL;
51  T* get() { return static_cast<T*>(getInstance()); }
52 
53  // set - Associates a pointer to an object with the current thread.
54  void set(T* d) { setInstance(d); }
55 
56  // erase - Removes the pointer associated with the current thread.
57  void erase() { removeInstance(); }
58  };
59  }
60 }
61 
62 #endif
llvm
---------------------— PointerInfo ------------------------------------—
Definition: AllocatorList.h:23
llvm::sys::ThreadLocalImpl::removeInstance
void removeInstance()
T
#define T
Definition: Mips16ISelLowering.cpp:341
llvm::sys::ThreadLocalImpl::getInstance
void * getInstance()
llvm::sys::ThreadLocalImpl::ThreadLocalImpl
ThreadLocalImpl()
llvm::sys::ThreadLocalImpl::setInstance
void setInstance(const void *d)
Threading.h
uint64_t
llvm::sys::ThreadLocalImpl::~ThreadLocalImpl
virtual ~ThreadLocalImpl()
llvm::sys::ThreadLocal::get
T * get()
get - Fetches a pointer to the object associated with the current thread.
Definition: ThreadLocal.h:51
llvm::sys::ThreadLocalImpl::align_data
ThreadLocalDataTy align_data
Definition: ThreadLocal.h:32
llvm::sys::ThreadLocal::ThreadLocal
ThreadLocal()
Definition: ThreadLocal.h:47
llvm::sys::ThreadLocalImpl
Definition: ThreadLocal.h:24
llvm::sys::ThreadLocal
ThreadLocal - A class used to abstract thread-local storage.
Definition: ThreadLocal.h:45
DataTypes.h
llvm::sys::ThreadLocal::erase
void erase()
Definition: ThreadLocal.h:57
d
the resulting code requires compare and branches when and if the revised code is with conditional branches instead of More there is a byte word extend before each where there should be only and the condition codes are not remembered when the same two values are compared twice More LSR enhancements i8 and i32 load store addressing modes are identical int int int d
Definition: README.txt:418
llvm::sys::ThreadLocal::set
void set(T *d)
Definition: ThreadLocal.h:54
llvm::sys::ThreadLocalImpl::data
char data[sizeof(ThreadLocalDataTy)]
Definition: ThreadLocal.h:31