LLVM 19.0.0git
Public Member Functions | Protected Attributes | List of all members
llvm::parallel::PerThreadAllocator< AllocatorTy > Class Template Reference

PerThreadAllocator is used in conjunction with ThreadPoolExecutor to allow per-thread allocations. More...

#include "llvm/Support/PerThreadBumpPtrAllocator.h"

Inheritance diagram for llvm::parallel::PerThreadAllocator< AllocatorTy >:
Inheritance graph
[legend]

Public Member Functions

 PerThreadAllocator ()
 
void * Allocate (size_t Size, size_t Alignment)
 Allocate Size bytes of Alignment aligned memory.
 
void Deallocate (const void *Ptr, size_t Size, size_t Alignment)
 Deallocate Ptr to Size bytes of memory allocated by this allocator.
 
AllocatorTy & getThreadLocalAllocator ()
 Return allocator corresponding to the current thread.
 
size_t getNumberOfAllocators () const
 
void Reset ()
 Reset state of allocators.
 
size_t getTotalMemory () const
 Return total memory size used by all allocators.
 
size_t getBytesAllocated () const
 Return allocated size by all allocators.
 
void setRedZoneSize (size_t NewSize)
 Set red zone for all allocators.
 
void PrintStats () const
 Print statistic for each allocator.
 
- Public Member Functions inherited from llvm::AllocatorBase< PerThreadAllocator< AllocatorTy > >
void * Allocate (size_t Size, size_t Alignment)
 Allocate Size bytes of Alignment aligned memory.
 
TAllocate (size_t Num=1)
 Allocate space for a sequence of objects without constructing them.
 
void Deallocate (const void *Ptr, size_t Size, size_t Alignment)
 Deallocate Ptr to Size bytes of memory allocated by this allocator.
 
std::enable_if_t<!std::is_same_v< std::remove_cv_t< T >, void >, void > Deallocate (T *Ptr, size_t Num=1)
 Deallocate space for a sequence of objects without constructing them.
 

Protected Attributes

size_t NumOfAllocators
 
std::unique_ptr< AllocatorTy[]> Allocators
 

Detailed Description

template<typename AllocatorTy>
class llvm::parallel::PerThreadAllocator< AllocatorTy >

PerThreadAllocator is used in conjunction with ThreadPoolExecutor to allow per-thread allocations.

It wraps a possibly thread-unsafe allocator, e.g. BumpPtrAllocator. PerThreadAllocator must be used with only main thread or threads created by ThreadPoolExecutor, as it utilizes getThreadIndex, which is set by ThreadPoolExecutor. To work properly, ThreadPoolExecutor should be initialized before PerThreadAllocator is created. TODO: The same approach might be implemented for ThreadPool.

Definition at line 27 of file PerThreadBumpPtrAllocator.h.

Constructor & Destructor Documentation

◆ PerThreadAllocator()

template<typename AllocatorTy >
llvm::parallel::PerThreadAllocator< AllocatorTy >::PerThreadAllocator ( )
inline

Definition at line 30 of file PerThreadBumpPtrAllocator.h.

Member Data Documentation

◆ Allocators

template<typename AllocatorTy >
std::unique_ptr<AllocatorTy[]> llvm::parallel::PerThreadAllocator< AllocatorTy >::Allocators
protected

◆ NumOfAllocators

template<typename AllocatorTy >
size_t llvm::parallel::PerThreadAllocator< AllocatorTy >::NumOfAllocators
protected

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