LLVM 22.0.0git
llvm::ThreadSafeAllocator< AllocatorType > Class Template Reference

Thread-safe allocator adaptor. More...

#include "llvm/Support/ThreadSafeAllocator.h"

Inheritance diagram for llvm::ThreadSafeAllocator< AllocatorType >:
[legend]

Public Member Functions

auto Allocate (size_t N)
auto Allocate (size_t Size, size_t Align)
template<typename FnT, typename T = typename llvm::function_traits<FnT>::result_t>
T applyLocked (FnT Fn)

Detailed Description

template<class AllocatorType>
class llvm::ThreadSafeAllocator< AllocatorType >

Thread-safe allocator adaptor.

Uses a spin lock on the assumption that contention here is extremely rare.

TODO: Using a spin lock on every allocation can be quite expensive when contention is high. Since this is mainly used for BumpPtrAllocator and SpecificBumpPtrAllocator, it'd be better to have a specific thread-safe BumpPtrAllocator implementation that only use a fair lock when allocating a new slab but otherwise using atomic and be lock-free.

Definition at line 26 of file ThreadSafeAllocator.h.

Member Function Documentation

◆ Allocate() [1/2]

template<class AllocatorType>
auto llvm::ThreadSafeAllocator< AllocatorType >::Allocate ( size_t N)
inline

Definition at line 38 of file ThreadSafeAllocator.h.

References applyLocked(), and N.

◆ Allocate() [2/2]

template<class AllocatorType>
auto llvm::ThreadSafeAllocator< AllocatorType >::Allocate ( size_t Size,
size_t Align )
inline

Definition at line 42 of file ThreadSafeAllocator.h.

References applyLocked(), and Size.

◆ applyLocked()

template<class AllocatorType>
template<typename FnT, typename T = typename llvm::function_traits<FnT>::result_t>
T llvm::ThreadSafeAllocator< AllocatorType >::applyLocked ( FnT Fn)
inline

Definition at line 50 of file ThreadSafeAllocator.h.

References T.

Referenced by Allocate(), and Allocate().


The documentation for this class was generated from the following file: