ATLAS Offline Software
Public Member Functions | Static Public Member Functions | Private Attributes | List of all members
SG::ArenaHeader Class Reference

Proxy for a group of Arenas. More...

#include <ArenaHeader.h>

Collaboration diagram for SG::ArenaHeader:

Public Member Functions

 ArenaHeader ()
 Constructor. More...
 
 ~ArenaHeader ()
 Destructor. More...
 
LockedAllocator allocator (size_t i)
 Translate an integer index to an Allocator pointer. More...
 
LockedAllocator allocator (const EventContext &ctx, size_t i)
 Translate an integer index to an Allocator pointer. More...
 
ArenaBasesetArena (ArenaBase *arena)
 Set the current Arena for the current thread. More...
 
void addArena (ArenaBase *a)
 Add a new Arena to the group. More...
 
void setArenaForSlot (int slot, ArenaBase *a)
 Record the arena associated with an event slot. More...
 
void delArena (ArenaBase *a)
 Remove an Arena from the group. More...
 
void report (std::ostream &os) const
 Generate a report of all Arenas in the group. More...
 
std::string reportStr () const
 Generate a report of all Arenas in the group, and return the result as a string. More...
 
void reset ()
 Call reset on all Allocators in the current Arena. More...
 

Static Public Member Functions

static ArenaHeaderdefaultHeader ()
 Return the global default Header instance. More...
 

Private Attributes

boost::thread_specific_ptr< ArenaBasem_arena
 Current Arena. More...
 
ArenaBase m_defaultArena
 The default Arena. More...
 
std::vector< ArenaBase * > m_arenas
 List of all Arenas in our group. More...
 
std::vector< ArenaBase * > m_slots
 Arenas indexed by event slot. More...
 
std::mutex m_mutex
 Mutex to protect access to m_defaultArena, m_arenas, and m_slots. More...
 

Detailed Description

Proxy for a group of Arenas.

See Arena.h for an overview of the arena-based memory allocators.

A Header collects a group of Arenas. One of these is the current Arena, in which memory operations will take place. We can also generate a report of memory usage from all the Arenas in the group.

We keep a thread-specific pointer to the current Arena, which is used to handle the mapping from indices to Allocator instances.

Definition at line 53 of file ArenaHeader.h.

Constructor & Destructor Documentation

◆ ArenaHeader()

SG::ArenaHeader::ArenaHeader ( )

Constructor.

Definition at line 34 of file ArenaHeader.cxx.

38 {
39 }

◆ ~ArenaHeader()

SG::ArenaHeader::~ArenaHeader ( )

Destructor.

This will clean up any memory allocated in the default Arena.

Definition at line 47 of file ArenaHeader.cxx.

48 {
49  // We don't own this.
50  m_arena.release();
51 }

Member Function Documentation

◆ addArena()

void SG::ArenaHeader::addArena ( ArenaBase a)

Add a new Arena to the group.

Parameters
aThe Arena to add.

Definition at line 72 of file ArenaHeader.cxx.

73 {
74  std::lock_guard<std::mutex> lock (m_mutex);
75  m_arenas.push_back (a);
76 }

◆ allocator() [1/2]

LockedAllocator SG::ArenaHeader::allocator ( const EventContext &  ctx,
size_t  i 
)

Translate an integer index to an Allocator pointer.

Parameters
ctxUse the Arena associated with this event context.
iThe index to look up.

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

◆ allocator() [2/2]

LockedAllocator SG::ArenaHeader::allocator ( size_t  i)

Translate an integer index to an Allocator pointer.

Parameters
iThe index to look up.

The default Arena will be used.

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

◆ defaultHeader()

ArenaHeader * SG::ArenaHeader::defaultHeader ( )
static

Return the global default Header instance.

Definition at line 164 of file ArenaHeader.cxx.

165 {
167  return &head;
168 }

◆ delArena()

void SG::ArenaHeader::delArena ( ArenaBase a)

Remove an Arena from the group.

Parameters
aThe Arena to remove.

Will trip an assertion if the Arena is not in the group.

Definition at line 101 of file ArenaHeader.cxx.

102 {
103  std::lock_guard<std::mutex> lock (m_mutex);
105  std::find (m_arenas.begin(), m_arenas.end(), a);
106  assert (it != m_arenas.end());
107  m_arenas.erase (it);
108 }

◆ report()

void SG::ArenaHeader::report ( std::ostream &  os) const

Generate a report of all Arenas in the group.

Parameters
osStream to which to send a report.

Definition at line 115 of file ArenaHeader.cxx.

116 {
117  std::lock_guard<std::mutex> lock (m_mutex);
118  // All Allocators in the group.
119  for (ArenaBase* arena : m_arenas) {
120  os << "=== " << arena->name() << " ===" << std::endl;
121  arena->report (os);
122  }
123 
124  // The default Arena.
125  os << "=== default ===" << std::endl;
127 }

◆ reportStr()

std::string SG::ArenaHeader::reportStr ( ) const

Generate a report of all Arenas in the group, and return the result as a string.

We have this in addition to report() in order to make it easier to call from scripting languages.

Definition at line 137 of file ArenaHeader.cxx.

138 {
139  std::ostringstream s;
140  report (s);
141  return s.str();
142 }

◆ reset()

void SG::ArenaHeader::reset ( )

Call reset on all Allocators in the current Arena.

All elements allocated are returned to the free state. clear should be called on them if it was provided. The elements may continue to be cached internally, without returning to the system.

Definition at line 153 of file ArenaHeader.cxx.

154 {
155  if (m_arena.get()) {
156  m_arena->reset();
157  }
158 }

◆ setArena()

ArenaBase * SG::ArenaHeader::setArena ( ArenaBase arena)

Set the current Arena for the current thread.

Parameters
arenaNew current Arena.
Returns
The previous Arena.

Definition at line 59 of file ArenaHeader.cxx.

60 {
61  ArenaBase* ret = m_arena.get();
62  m_arena.release();
63  m_arena.reset (arena);
64  return ret;
65 }

◆ setArenaForSlot()

void SG::ArenaHeader::setArenaForSlot ( int  slot,
ArenaBase a 
)

Record the arena associated with an event slot.

Parameters
slotThe slot number.
aThe Arena instance.

Definition at line 84 of file ArenaHeader.cxx.

85 {
86  if (slot < 0) return;
87  std::lock_guard<std::mutex> lock (m_mutex);
88  if (slot >= static_cast<int> (m_slots.size())) {
89  m_slots.resize (slot+1);
90  }
91  m_slots[slot] = a;
92 }

Member Data Documentation

◆ m_arena

boost::thread_specific_ptr<ArenaBase> SG::ArenaHeader::m_arena
private

Current Arena.

Definition at line 159 of file ArenaHeader.h.

◆ m_arenas

std::vector<ArenaBase*> SG::ArenaHeader::m_arenas
private

List of all Arenas in our group.

Definition at line 165 of file ArenaHeader.h.

◆ m_defaultArena

ArenaBase SG::ArenaHeader::m_defaultArena
private

The default Arena.

Definition at line 162 of file ArenaHeader.h.

◆ m_mutex

std::mutex SG::ArenaHeader::m_mutex
mutableprivate

Mutex to protect access to m_defaultArena, m_arenas, and m_slots.

Definition at line 171 of file ArenaHeader.h.

◆ m_slots

std::vector<ArenaBase*> SG::ArenaHeader::m_slots
private

Arenas indexed by event slot.

Definition at line 168 of file ArenaHeader.h.


The documentation for this class was generated from the following files:
xAOD::iterator
JetConstituentVector::iterator iterator
Definition: JetConstituentVector.cxx:68
SG::null_arena_deleter
void null_arena_deleter(ArenaBase *)
Definition: ArenaHeader.cxx:28
SG::ArenaHeader::m_mutex
std::mutex m_mutex
Mutex to protect access to m_defaultArena, m_arenas, and m_slots.
Definition: ArenaHeader.h:171
python.SystemOfUnits.s
int s
Definition: SystemOfUnits.py:131
find
std::string find(const std::string &s)
return a remapped string
Definition: hcg.cxx:135
skel.it
it
Definition: skel.GENtoEVGEN.py:396
SG::ArenaBase::report
void report(std::ostream &os) const
Generate a report of the memory in use by this Arena.
Definition: ArenaBase.cxx:76
SG::ArenaHeader::report
void report(std::ostream &os) const
Generate a report of all Arenas in the group.
Definition: ArenaHeader.cxx:115
SG::ArenaHeader::m_arena
boost::thread_specific_ptr< ArenaBase > m_arena
Current Arena.
Definition: ArenaHeader.h:159
ReadFromCoolCompare.os
os
Definition: ReadFromCoolCompare.py:231
head
std::string head(std::string s, const std::string &pattern)
head of a string
Definition: computils.cxx:310
SG::ArenaHeader::ArenaHeader
ArenaHeader()
Constructor.
Definition: ArenaHeader.cxx:34
SG::ArenaHeader::m_slots
std::vector< ArenaBase * > m_slots
Arenas indexed by event slot.
Definition: ArenaHeader.h:168
a
TList * a
Definition: liststreamerinfos.cxx:10
SG::ArenaHeader::m_arenas
std::vector< ArenaBase * > m_arenas
List of all Arenas in our group.
Definition: ArenaHeader.h:165
SG::ArenaHeader::m_defaultArena
ArenaBase m_defaultArena
The default Arena.
Definition: ArenaHeader.h:162
ATLAS_THREAD_SAFE
#define ATLAS_THREAD_SAFE
Definition: checker_macros.h:211