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

Go to the documentation of this file.

1

2

3

4

5

6

7

8

9#ifndef LLVM_SUPPORT_THREADSAFEALLOCATOR_H

10#define LLVM_SUPPORT_THREADSAFEALLOCATOR_H

11

14#include

15

16namespace llvm {

17

18

19

20

21

22

23

24

25

27 struct LockGuard {

28 LockGuard(std::atomic_flag &Flag) : Flag(Flag) {

29 if (LLVM_UNLIKELY(Flag.test_and_set(std::memory_order_acquire)))

30 while (Flag.test_and_set(std::memory_order_acquire)) {

31 }

32 }

33 ~LockGuard() { Flag.clear(std::memory_order_release); }

34 std::atomic_flag &Flag;

35 };

36

37public:

39 return applyLocked([N](AllocatorType &Alloc) { return Alloc.Allocate(N); });

40 }

41

44 return Alloc.Allocate(Size, Align);

45 });

46 }

47

48 template <typename FnT,

51 LockGuard Lock(Flag);

52 return Fn(Alloc);

53 }

54

55private:

56 AllocatorType Alloc;

57 std::atomic_flag Flag = ATOMIC_FLAG_INIT;

58};

59

60}

61

62#endif

This file defines the BumpPtrAllocator interface.

#define LLVM_UNLIKELY(EXPR)

Thread-safe allocator adaptor.

Definition ThreadSafeAllocator.h:26

auto Allocate(size_t Size, size_t Align)

Definition ThreadSafeAllocator.h:42

auto Allocate(size_t N)

Definition ThreadSafeAllocator.h:38

T applyLocked(FnT Fn)

Definition ThreadSafeAllocator.h:50

This is an optimization pass for GlobalISel generic memory operations.

This struct is a compact representation of a valid (non-zero power of two) alignment.

This class provides various trait information about a callable object.