ATLAS Offline Software
Loading...
Searching...
No Matches
SG::ArenaHeader Class Reference

Proxy for a group of Arenas. More...

#include <ArenaHeader.h>

Collaboration diagram for SG::ArenaHeader:

Public Member Functions

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

Static Public Member Functions

static ArenaHeaderdefaultHeader ()
 Return the global default Header instance.

Private Attributes

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

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}
boost::thread_specific_ptr< ArenaBase > m_arena
Current Arena.
void null_arena_deleter(ArenaBase *)

◆ ~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}
static Double_t a
std::vector< ArenaBase * > m_arenas
List of all Arenas in our group.
std::mutex m_mutex
Mutex to protect access to m_defaultArena, m_arenas, and m_slots.

◆ 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}
#define ATLAS_THREAD_SAFE
ArenaHeader()
Constructor.
std::string head(std::string s, const std::string &pattern)
head of a string

◆ 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);
104 std::vector<ArenaBase*>::iterator it =
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;
126 m_defaultArena.report (os);
127}
ArenaBase m_defaultArena
The default Arena.

◆ 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}
void report(std::ostream &os) const
Generate a report of all Arenas in the group.

◆ 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}
std::vector< ArenaBase * > m_slots
Arenas indexed by event slot.

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: