ATLAS Offline Software
ArenaBase.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
3 */
17 #include <ostream>
18 
19 
20 namespace SG {
21 
22 
27 ArenaBase::ArenaBase (const std::string& name /*= ""*/)
28  : m_name (name)
29 {
30 }
31 
32 
37 {
38 }
39 
40 
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 }
54 
55 
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 }
70 
71 
76 void ArenaBase::report (std::ostream& os) const
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 }
92 
93 
98 {
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 }
109 
110 
114 const std::string& ArenaBase::name() const
115 {
116  return m_name;
117 }
118 
119 
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 }
148 
149 
150 } // namespace SG
SG::ArenaAllocatorRegistry::instance
static ArenaAllocatorRegistry * instance()
Return a pointer to the global ArenaAllocatorRegistry instance.
Definition: ArenaAllocatorRegistry.cxx:204
SG::ArenaBase::~ArenaBase
virtual ~ArenaBase()
Destructor.
Definition: ArenaBase.cxx:36
SG
Forward declaration.
Definition: CaloCellPacker_400_500.h:32
SG::ArenaBase::m_allocs
std::vector< AllocEntry > m_allocs
Definition: ArenaBase.h:124
UploadAMITag.l
list l
Definition: UploadAMITag.larcaf.py:158
SG::ArenaBase::makeAllocator
ArenaAllocatorBase * makeAllocator(size_t i)
Make a new Allocator for index i.
Definition: ArenaBase.cxx:130
SG::ArenaBase::ArenaBase
ArenaBase(const std::string &name="")
Constructor.
Definition: ArenaBase.cxx:27
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::ArenaAllocatorBase::Stats
Statistics for an allocator.
Definition: ArenaAllocatorBase.h:188
lumiFormat.i
int i
Definition: lumiFormat.py:85
SG::ArenaBase::m_name
std::string m_name
Our name.
Definition: ArenaBase.h:127
SG::ArenaBase::reset
void reset()
Reset all contained allocators.
Definition: ArenaBase.cxx:44
ArenaAllocatorBase.h
Common base class for arena allocator classes. See Arena.h for an overview of the arena-based memory ...
SG::ArenaAllocatorRegistry::create
std::unique_ptr< ArenaAllocatorBase > create(size_t i)
Create a new instance of an allocator.
Definition: ArenaAllocatorRegistry.cxx:195
SG::ArenaAllocatorBase
Common base class for arena allocator classes.
Definition: ArenaAllocatorBase.h:134
SG::ArenaBase::erase
void erase()
Erase all contained allocators.
Definition: ArenaBase.cxx:60
ReadFromCoolCompare.os
os
Definition: ReadFromCoolCompare.py:231
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:221
ArenaBase.h
Part of Arena dealing with the list of allocators. Broken out from Arena to avoid a dependency loop w...
DeMoScan.first
bool first
Definition: DeMoScan.py:536
SG::ArenaAllocatorBase::Stats::header
static void header(std::ostream &os)
Print report header.
Definition: ArenaAllocatorBase.cxx:117
SG::ArenaBase::lock_t
std::lock_guard< std::mutex > lock_t
Definition: ArenaBase.h:102
SG::ArenaBase::stats
ArenaAllocatorBase::Stats stats() const
Return statistics summed over all allocators in this Arena.
Definition: ArenaBase.cxx:97
ArenaAllocatorRegistry.h
Registry of allocator factories. See Arena.h for an overview of the arena-based memory allocators.
SG::ArenaBase::m_mutex
std::mutex m_mutex
To guard access to m_allocs.
Definition: ArenaBase.h:130
SG::ArenaBase::AllocEntry
Our allocator vector.
Definition: ArenaBase.h:120
SG::ArenaBase::name
const std::string & name() const
Return this Arena's name.
Definition: ArenaBase.cxx:114