LLVM 22.0.0git
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 >:
[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.
void Deallocate (const void *Ptr, size_t Size, size_t Alignment)
 Deallocate Ptr to Size bytes of memory allocated by this allocator.

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

Definition at line 112 of file PerThreadBumpPtrAllocator.h.

◆ NumOfAllocators

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

Definition at line 111 of file PerThreadBumpPtrAllocator.h.


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