ATLAS Offline Software
Classes | Public Member Functions | Private Types | Private Member Functions | Private Attributes | List of all members
SG::Arena Class Reference

Collection of memory allocators with a common lifetime,. More...

#include <Arena.h>

Inheritance diagram for SG::Arena:
Collaboration diagram for SG::Arena:

Classes

class  Push
 Helper class for making Arena instances current in a stack-like manner. More...
 

Public Member Functions

 Arena (const std::string &name, ArenaHeader *header=0)
 Constructor. More...
 
 ~Arena ()
 Destructor. More...
 
ArenaHeaderheader ()
 Return the ArenaHeader with which this Arena is associated. More...
 
ArenaBasemakeCurrent ()
 Make this Arena the current one for its ArenaHeader. More...
 
LockedAllocator allocator (size_t i)
 Translate an integer index to an Allocator pointer. More...
 
void reset ()
 Reset all contained allocators. More...
 
void erase ()
 Erase all contained allocators. More...
 
void report (std::ostream &os) const
 Generate a report of the memory in use by this Arena. More...
 
ArenaAllocatorBase::Stats stats () const
 Return statistics summed over all allocators in this Arena. More...
 
const std::string & name () const
 Return this Arena's name. More...
 

Private Types

typedef std::lock_guard< std::mutex > lock_t
 

Private Member Functions

ArenaAllocatorBasemakeAllocator (size_t i)
 Make a new Allocator for index i. More...
 

Private Attributes

ArenaHeaderm_header
 The ArenaHeader with which we're associated. More...
 
std::vector< AllocEntrym_allocs
 
std::string m_name
 Our name. More...
 
std::mutex m_mutex
 To guard access to m_allocs. More...
 

Detailed Description

Collection of memory allocators with a common lifetime,.

See the file-level comments for a full description.

Definition at line 236 of file Arena.h.

Member Typedef Documentation

◆ lock_t

typedef std::lock_guard<std::mutex> SG::ArenaBase::lock_t
privateinherited

Definition at line 102 of file ArenaBase.h.

Constructor & Destructor Documentation

◆ Arena()

SG::Arena::Arena ( const std::string &  name,
ArenaHeader header = 0 
)

Constructor.

Parameters
nameThe name of this Arena; to use in reports.
headerThe header with which this Arena is associated. If defaulted, the global default ArenaHeader will be used.

Definition at line 26 of file Arena.cxx.

27  : ArenaBase (name),
29 {
30  if (!m_header) {
32  }
33  m_header->addArena (this);
34 }

◆ ~Arena()

SG::Arena::~Arena ( )

Destructor.

Definition at line 40 of file Arena.cxx.

41 {
42  m_header->delArena (this);
43 }

Member Function Documentation

◆ allocator()

LockedAllocator SG::ArenaBase::allocator ( size_t  i)
inherited

Translate an integer index to an Allocator pointer.

Parameters
iThe index to look up.

If the index isn't valid, an assertion will be tripped.

◆ erase()

void SG::ArenaBase::erase ( )
inherited

Erase all contained allocators.

All elements will be freed, and the memory returned to the system.

Definition at line 60 of file ArenaBase.cxx.

61 {
62  lock_t l (m_mutex);
63  for (AllocEntry& alloc : m_allocs) {
64  if (alloc.m_alloc) {
65  lock_t alloc_lock (*alloc.m_mutex);
66  alloc.m_alloc->erase();
67  }
68  }
69 }

◆ header()

ArenaHeader * SG::Arena::header ( )

Return the ArenaHeader with which this Arena is associated.

Definition at line 49 of file Arena.cxx.

50 {
51  return m_header;
52 }

◆ makeAllocator()

ArenaAllocatorBase * SG::ArenaBase::makeAllocator ( size_t  i)
privateinherited

Make a new Allocator for index i.

Parameters
iThe index of the Allocator.

The Allocator vector was empty for index i. Make an appropriate new Allocator, store it in the vector, and return it. Will trip an assertion if the index is not valid.

This should be called with m_mutex held.

Definition at line 130 of file ArenaBase.cxx.

131 {
132  // We have to create a new Allocator.
133  // Make sure there's room in the vector.
134  if (m_allocs.size() <= i) {
135  m_allocs.resize (i+1);
136  }
137 
138  // Create the Allocator, using the Registry.
139  std::unique_ptr<ArenaAllocatorBase> alloc =
141 
142  // Install it in the vector.
143  m_allocs[i].m_alloc = std::move (alloc);
144  m_allocs[i].m_mutex = std::make_unique<std::mutex>();
145 
146  return m_allocs[i].m_alloc.get();
147 }

◆ makeCurrent()

ArenaBase * SG::Arena::makeCurrent ( )

Make this Arena the current one for its ArenaHeader.

Returns
The previously current Arena.

Definition at line 59 of file Arena.cxx.

60 {
61  return m_header->setArena (this);
62 }

◆ name()

const std::string & SG::ArenaBase::name ( ) const
inherited

Return this Arena's name.

Definition at line 114 of file ArenaBase.cxx.

115 {
116  return m_name;
117 }

◆ report()

void SG::ArenaBase::report ( std::ostream &  os) const
inherited

Generate a report of the memory in use by this Arena.

Parameters
osThe stream to which to write the report.

Definition at line 76 of file ArenaBase.cxx.

77 {
78  lock_t l (m_mutex);
79  bool first = true;
80  for (const AllocEntry& alloc : m_allocs) {
81  if (alloc.m_alloc) {
82  if (first) {
84  os << std::endl;
85  first = false;
86  }
87  lock_t alloc_lock (*alloc.m_mutex);
88  alloc.m_alloc->report (os);
89  }
90  }
91 }

◆ reset()

void SG::ArenaBase::reset ( )
inherited

Reset all contained allocators.

All elements will be freed.

Definition at line 44 of file ArenaBase.cxx.

45 {
46  lock_t l (m_mutex);
47  for (AllocEntry& alloc : m_allocs) {
48  if (alloc.m_alloc) {
49  lock_t alloc_lock (*alloc.m_mutex);
50  alloc.m_alloc->reset();
51  }
52  }
53 }

◆ stats()

ArenaAllocatorBase::Stats SG::ArenaBase::stats ( ) const
inherited

Return statistics summed over all allocators in this Arena.

Definition at line 97 of file ArenaBase.cxx.

98 {
99  ArenaAllocatorBase::Stats stats;
100  lock_t l (m_mutex);
101  for (const AllocEntry& alloc : m_allocs) {
102  if (alloc.m_alloc) {
103  lock_t alloc_lock (*alloc.m_mutex);
104  stats += alloc.m_alloc->stats();
105  }
106  }
107  return stats;
108 }

Member Data Documentation

◆ m_allocs

std::vector<AllocEntry> SG::ArenaBase::m_allocs
privateinherited

Definition at line 124 of file ArenaBase.h.

◆ m_header

ArenaHeader* SG::Arena::m_header
private

The ArenaHeader with which we're associated.

Definition at line 300 of file Arena.h.

◆ m_mutex

std::mutex SG::ArenaBase::m_mutex
mutableprivateinherited

To guard access to m_allocs.

Definition at line 130 of file ArenaBase.h.

◆ m_name

std::string SG::ArenaBase::m_name
privateinherited

Our name.

Definition at line 127 of file ArenaBase.h.


The documentation for this class was generated from the following files:
SG::ArenaAllocatorRegistry::instance
static ArenaAllocatorRegistry * instance()
Return a pointer to the global ArenaAllocatorRegistry instance.
Definition: ArenaAllocatorRegistry.cxx:204
header
Definition: hcg.cxx:526
SG::ArenaBase::m_allocs
std::vector< AllocEntry > m_allocs
Definition: ArenaBase.h:124
UploadAMITag.l
list l
Definition: UploadAMITag.larcaf.py:158
SG::ArenaBase::ArenaBase
ArenaBase(const std::string &name="")
Constructor.
Definition: ArenaBase.cxx:27
lumiFormat.i
int i
Definition: lumiFormat.py:85
SG::ArenaBase::m_name
std::string m_name
Our name.
Definition: ArenaBase.h:127
SG::ArenaAllocatorRegistry::create
std::unique_ptr< ArenaAllocatorBase > create(size_t i)
Create a new instance of an allocator.
Definition: ArenaAllocatorRegistry.cxx:195
ReadFromCoolCompare.os
os
Definition: ReadFromCoolCompare.py:231
SG::ArenaHeader::defaultHeader
static ArenaHeader * defaultHeader()
Return the global default Header instance.
Definition: ArenaHeader.cxx:164
DeMoScan.first
bool first
Definition: DeMoScan.py:536
SG::ArenaHeader::delArena
void delArena(ArenaBase *a)
Remove an Arena from the group.
Definition: ArenaHeader.cxx:101
SG::ArenaAllocatorBase::Stats::header
static void header(std::ostream &os)
Print report header.
Definition: ArenaAllocatorBase.cxx:117
SG::Arena::m_header
ArenaHeader * m_header
The ArenaHeader with which we're associated.
Definition: Arena.h:300
SG::ArenaBase::lock_t
std::lock_guard< std::mutex > lock_t
Definition: ArenaBase.h:102
SG::ArenaHeader::setArena
ArenaBase * setArena(ArenaBase *arena)
Set the current Arena for the current thread.
Definition: ArenaHeader.cxx:59
SG::ArenaBase::stats
ArenaAllocatorBase::Stats stats() const
Return statistics summed over all allocators in this Arena.
Definition: ArenaBase.cxx:97
SG::ArenaBase::m_mutex
std::mutex m_mutex
To guard access to m_allocs.
Definition: ArenaBase.h:130
SG::ArenaHeader::addArena
void addArena(ArenaBase *a)
Add a new Arena to the group.
Definition: ArenaHeader.cxx:72
SG::ArenaBase::name
const std::string & name() const
Return this Arena's name.
Definition: ArenaBase.cxx:114