LLVM: include/llvm/Support/ManagedStatic.h Source File (original) (raw)

1

2

3

4

5

6

7

8

9

10

11

12

13#ifndef LLVM_SUPPORT_MANAGEDSTATIC_H

14#define LLVM_SUPPORT_MANAGEDSTATIC_H

15

17#include

18#include

19

20namespace llvm {

21

22

24 static void *call() { return new C(); }

25};

26

27

28

30 static void call(void *Ptr) { delete (T *)Ptr; }

31};

33 static void call(void *Ptr) { delete[](T *)Ptr; }

34};

35

36

37

38

39

40

41

42

43

44

45#if !defined(_MSC_VER) || (_MSC_VER >= 1925) || defined(__clang__)

46#define LLVM_USE_CONSTEXPR_CTOR

47#endif

48

49

51protected:

52#ifdef LLVM_USE_CONSTEXPR_CTOR

53 mutable std::atomic<void *> Ptr{};

54 mutable void (*DeleterFn)(void *) = nullptr;

56#else

57

58

59 mutable std::atomic<void *> Ptr;

60 mutable void (*DeleterFn)(void *);

62#endif

63

65 void (*deleter)(void *)) const;

66

67public:

68#ifdef LLVM_USE_CONSTEXPR_CTOR

70#endif

71

72

74

76};

77

78

79

80

81

82

83template <class C, class Creator = object_creator,

84 class Deleter = object_deleter>

86public:

87

89 void *Tmp = Ptr.load(std::memory_order_acquire);

90 if (!Tmp)

92

93 return *static_cast<C *>(Ptr.load(std::memory_order_relaxed));

94 }

95

97

99 void *Tmp = Ptr.load(std::memory_order_acquire);

100 if (!Tmp)

102

103 return *static_cast<C *>(Ptr.load(std::memory_order_relaxed));

104 }

105

107

108

109

111 return static_cast<C *>(Ptr.exchange(nullptr));

112 }

113};

114

115

117

118

119

124

125}

126

127#endif

LLVM_ABI void RegisterManagedStatic(void *(*creator)(), void(*deleter)(void *)) const

constexpr ManagedStaticBase()=default

void(* DeleterFn)(void *)

Definition ManagedStatic.h:54

const ManagedStaticBase * Next

Definition ManagedStatic.h:55

std::atomic< void * > Ptr

Definition ManagedStatic.h:53

bool isConstructed() const

isConstructed - Return true if this object has not been created yet.

Definition ManagedStatic.h:73

LLVM_ABI void destroy() const

ManagedStatic - This transparently changes the behavior of global statics to be lazily constructed on...

Definition ManagedStatic.h:85

const C * operator->() const

Definition ManagedStatic.h:106

const C & operator*() const

Definition ManagedStatic.h:98

C * claim()

Definition ManagedStatic.h:110

C * operator->()

Definition ManagedStatic.h:96

C & operator*()

Definition ManagedStatic.h:88

@ C

The default llvm calling convention, compatible with C.

This is an optimization pass for GlobalISel generic memory operations.

LLVM_ABI void llvm_shutdown()

llvm_shutdown - Deallocate and destroy all ManagedStatic variables.

~llvm_shutdown_obj()

Definition ManagedStatic.h:122

llvm_shutdown_obj()=default

object_creator - Helper method for ManagedStatic.

Definition ManagedStatic.h:23

static void * call()

Definition ManagedStatic.h:24

static void call(void *Ptr)

Definition ManagedStatic.h:33

object_deleter - Helper method for ManagedStatic.

Definition ManagedStatic.h:29

static void call(void *Ptr)

Definition ManagedStatic.h:30