ATLAS Offline Software
ArenaBlock.h
Go to the documentation of this file.
1 // This file's extension implies that it's C, but it's really -*- C++ -*-.
2 /*
3  Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
4 */
13 #ifndef ATLALLOCATORS_ARENABLOCK_H
14 #define ATLALLOCATORS_ARENABLOCK_H
15 
16 
17 #include <cstdlib>
18 #include <atomic>
20 
21 namespace SG {
22 
23 
24 
25 class ArenaAllocatorBase;
26 
43 {
44 public:
46  typedef char* pointer;
47  typedef const char* const_pointer;
48 
50  typedef void func_t (pointer);
51 
52 
64  static ArenaBlock* newBlock (size_t n, size_t elt_size, func_t* ctor);
65 
66 
72  static void destroy (ArenaBlock* p, func_t* dtor);
73 
74 
82  static void destroyList (ArenaBlock* p, func_t* dtor);
83 
84 
94  static void appendList (ArenaBlock** headp, ArenaBlock* tail);
95 
96 
109  static void applyList (ArenaBlock* p, func_t* func, size_t n);
110 
111 
115  size_t size() const;
116 
117 
121  size_t eltSize() const;
122 
123 
128 
129 
133  const ArenaBlock* link() const;
134 
135 
140  pointer index (size_t i);
141 
142 
147  const_pointer index (size_t i) const;
148 
149 
159  pointer index (size_t i, size_t elt_size);
160 
161 
171  const_pointer index (size_t i, size_t elt_size) const;
172 
173 
180  static size_t overhead();
181 
182 
184  static size_t nactive();
185 
186 
193  void protect();
194 
195 
202  void unprotect();
203 
204 
212  static void protectList (ArenaBlock* p);
213 
214 
222  static void unprotectList (ArenaBlock* p);
223 
224 private:
226  ArenaBlock (size_t n, size_t elt_size);
230 
231  // This is not really needed. It's just to squelch the g++ warning
232  // about classes with all private ctors/dtors and no friends.
233  friend class ArenaAllocatorBase;
234 
237 
239  size_t m_size;
240 
242  size_t m_elt_size;
243 
244  // The start of the block body.
245  // Try to make sure it's aligned.
247 
249  static std::atomic<size_t> s_nactive;
250 };
251 
252 
254 static const int ArenaBlockBodyOffset =
256 
257 
258 } // namespace SG
259 
260 
262 
263 
264 #endif // not ATLALLOCATORS_ARENABLOCK_H
SG::ArenaBlock::func_t
void func_t(pointer)
Function that operates on an element.
Definition: ArenaBlock.h:50
SG::ArenaBlock::link
const ArenaBlock * link() const
Return the link pointer of the block.
SG::ArenaBlock::index
pointer index(size_t i)
Return a pointer to element i in the block.
SG::ArenaBlock::ArenaBlock
ArenaBlock(size_t n, size_t elt_size)
Prohibit calling these.
SG::ArenaBlock::unprotect
void unprotect()
Write-enable this block.
Definition: ArenaBlock.cxx:186
SG
Forward declaration.
Definition: CaloCellPacker_400_500.h:32
SG::ArenaBlock::destroy
static void destroy(ArenaBlock *p, func_t *dtor)
Destroy a block.
Definition: ArenaBlock.cxx:69
SG::ArenaBlock::~ArenaBlock
~ArenaBlock()
Definition: ArenaBlock.h:227
SG::ArenaBlock::ArenaBlock
ArenaBlock(const ArenaBlock &)
tail
std::string tail(std::string s, const std::string &pattern)
tail of a string
Definition: computils.cxx:301
SG::ArenaBlock::applyList
static void applyList(ArenaBlock *p, func_t *func, size_t n)
Call a function on elements in a list of blocks.
Definition: ArenaBlock.cxx:131
SG::ArenaBlock::overhead
static size_t overhead()
Return the per-block memory overhead, in bytes.
Definition: ArenaBlock.cxx:157
SG::ArenaBlock::eltSize
size_t eltSize() const
Return the size of the elements in the block.
SG::ArenaBlock::newBlock
static ArenaBlock * newBlock(size_t n, size_t elt_size, func_t *ctor)
Create a new block.
Definition: ArenaBlock.cxx:41
SG::ArenaBlock::appendList
static void appendList(ArenaBlock **headp, ArenaBlock *tail)
Concatenate two lists of blocks.
Definition: ArenaBlock.cxx:110
SG::ArenaBlock::unprotectList
static void unprotectList(ArenaBlock *p)
Write-enable all blocks in a list.
Definition: ArenaBlock.cxx:218
SG::ArenaBlock::index
const_pointer index(size_t i) const
Return a pointer to element i in the block.
SG::ArenaBlock::nactive
static size_t nactive()
Return the global number of blocks in use.
SG::ArenaBlock::link
ArenaBlock *& link()
Return the link pointer of the block.
SG::ArenaBlock::pointer
char * pointer
Type for a pointer to an element.
Definition: ArenaBlock.h:46
python.utils.AtlRunQueryDQUtils.p
p
Definition: AtlRunQueryDQUtils.py:210
SG::ArenaBlock::m_dummy
ArenaBlockAlignDetail::padForAlign m_dummy
Definition: ArenaBlock.h:246
lumiFormat.i
int i
Definition: lumiFormat.py:85
SG::ArenaBlock::size
size_t size() const
Return the number of elements in the block.
beamspotman.n
n
Definition: beamspotman.py:731
SG::ArenaBlock::m_size
size_t m_size
Number of elements in this block.
Definition: ArenaBlock.h:239
SG::ArenaAllocatorBase
Common base class for arena allocator classes.
Definition: ArenaAllocatorBase.h:134
SG::ArenaBlock::index
pointer index(size_t i, size_t elt_size)
Return a pointer to element i in the block.
SG::ArenaBlock::m_link
ArenaBlock * m_link
The link for the linked list.
Definition: ArenaBlock.h:236
SG::ArenaBlock::index
const_pointer index(size_t i, size_t elt_size) const
Return a pointer to element i in the block.
SG::ArenaBlock
A large memory block that gets carved into smaller uniform elements.
Definition: ArenaBlock.h:43
SG::ArenaBlock::s_nactive
static std::atomic< size_t > s_nactive
Global count of the number of blocks in use.
Definition: ArenaBlock.h:249
SG::ArenaBlock::m_elt_size
size_t m_elt_size
Size, in bytes, of each element in this block.
Definition: ArenaBlock.h:242
SG::ArenaBlockAlignDetail::padForAlign
Definition: ArenaBlockAlignDetail.h:24
SG::ArenaBlock::const_pointer
const char * const_pointer
Definition: ArenaBlock.h:47
SG::ArenaBlock::protectList
static void protectList(ArenaBlock *p)
Write-protect all blocks in a list.
Definition: ArenaBlock.cxx:203
SG::ArenaBlock::protect
void protect()
Write-protect this block.
Definition: ArenaBlock.cxx:170
SG::ArenaBlock::destroyList
static void destroyList(ArenaBlock *p, func_t *dtor)
Destroy all blocks in a list.
Definition: ArenaBlock.cxx:91
ArenaBlockAlignDetail.h
A dummy pad struct to put at the end of the ArenaBlock header to ensure the alignment of the elements...
SG::ArenaBlock::operator=
ArenaBlock & operator=(const ArenaBlock &)
ArenaBlock.icc