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

ArenaAllocatorRegistry implementation class. More...

Collaboration diagram for SG::ArenaAllocatorRegistryImpl:

Public Member Functions

 ~ArenaAllocatorRegistryImpl ()
 Destructor. More...
 
size_t registerCreator (const std::string &name, std::unique_ptr< ArenaAllocatorCreator > creator)
 Register a new allocator type. More...
 
size_t lookup (const std::string &name)
 Look up the index for an allocator type name. More...
 
std::unique_ptr< ArenaAllocatorBasecreate (size_t i)
 Create a new instance of an allocator. More...
 

Private Types

typedef std::map< std::string, size_t > map_t
 Map from names to indices. More...
 
typedef std::lock_guard< std::mutex > lock_t
 

Private Attributes

map_t m_map
 
std::vector< std::unique_ptr< ArenaAllocatorCreator > > m_creators
 Vector of factory instances. More...
 
std::mutex m_mutex
 Mutex to protect the contents. More...
 

Detailed Description

ArenaAllocatorRegistry implementation class.

Definition at line 30 of file ArenaAllocatorRegistry.cxx.

Member Typedef Documentation

◆ lock_t

typedef std::lock_guard<std::mutex> SG::ArenaAllocatorRegistryImpl::lock_t
private

Definition at line 79 of file ArenaAllocatorRegistry.cxx.

◆ map_t

typedef std::map<std::string, size_t> SG::ArenaAllocatorRegistryImpl::map_t
private

Map from names to indices.

Definition at line 70 of file ArenaAllocatorRegistry.cxx.

Constructor & Destructor Documentation

◆ ~ArenaAllocatorRegistryImpl()

SG::ArenaAllocatorRegistryImpl::~ArenaAllocatorRegistryImpl ( )

Destructor.

Definition at line 86 of file ArenaAllocatorRegistry.cxx.

87 {
88 }

Member Function Documentation

◆ create()

std::unique_ptr< ArenaAllocatorBase > SG::ArenaAllocatorRegistryImpl::create ( size_t  i)

Create a new instance of an allocator.

Parameters
iThe index of the allocator to create.
Returns
A newly-allocated allocator instance.

Definition at line 150 of file ArenaAllocatorRegistry.cxx.

151 {
152  lock_t lock (m_mutex);
153  assert (i < m_creators.size());
154  return m_creators[i]->create();
155 }

◆ lookup()

size_t SG::ArenaAllocatorRegistryImpl::lookup ( const std::string &  name)

Look up the index for an allocator type name.

Parameters
nameThe name of the allocator type to find.
Returns
The index corresponding to the type, or std::string::npos if it hasn't yet been registered.

Definition at line 133 of file ArenaAllocatorRegistry.cxx.

134 {
135  lock_t lock (m_mutex);
136  map_t::iterator it = m_map.find (name);
137  if (it == m_map.end()) {
138  return std::string::npos;
139  }
140  return it->second;
141 }

◆ registerCreator()

size_t SG::ArenaAllocatorRegistryImpl::registerCreator ( const std::string &  name,
std::unique_ptr< ArenaAllocatorCreator creator 
)

Register a new allocator type.

Parameters
nameThe name of the allocator type.
creatorThe factory object to create instances of this type. The registry takes ownership of this pointer.
Returns
The new integer index for this allocator type.

If the allocator type already exists, then the index of the existing one is returned (and the object passed as creator is deleted).

Definition at line 102 of file ArenaAllocatorRegistry.cxx.

104 {
105  lock_t lock (m_mutex);
106 
107  // See if there's an existing one by this name.
108  // Shouldn't usually happen, since we check that the allocator doesn't
109  // exist before calling this, but could happen in a MT job.
110  // So we need to check it again with the lock held.
111  map_t::iterator it = m_map.find (name);
112  if (it != m_map.end()) {
113  // creator will be deleted.
114  return it->second;
115  }
116 
117  // The new index.
118  size_t i = m_creators.size();
119 
120  // Remember the index and store the creator.
121  m_map[name] = i;
122  m_creators.push_back (std::move (creator));
123  return i;
124 }

Member Data Documentation

◆ m_creators

std::vector<std::unique_ptr<ArenaAllocatorCreator> > SG::ArenaAllocatorRegistryImpl::m_creators
private

Vector of factory instances.

Definition at line 74 of file ArenaAllocatorRegistry.cxx.

◆ m_map

map_t SG::ArenaAllocatorRegistryImpl::m_map
private

Definition at line 71 of file ArenaAllocatorRegistry.cxx.

◆ m_mutex

std::mutex SG::ArenaAllocatorRegistryImpl::m_mutex
private

Mutex to protect the contents.

Definition at line 77 of file ArenaAllocatorRegistry.cxx.


The documentation for this class was generated from the following file:
xAOD::iterator
JetConstituentVector::iterator iterator
Definition: JetConstituentVector.cxx:68
skel.it
it
Definition: skel.GENtoEVGEN.py:396
SG::ArenaAllocatorRegistryImpl::m_map
map_t m_map
Definition: ArenaAllocatorRegistry.cxx:71
lumiFormat.i
int i
Definition: lumiFormat.py:85
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:221
SG::ArenaAllocatorRegistryImpl::m_mutex
std::mutex m_mutex
Mutex to protect the contents.
Definition: ArenaAllocatorRegistry.cxx:77
SG::ArenaAllocatorRegistryImpl::m_creators
std::vector< std::unique_ptr< ArenaAllocatorCreator > > m_creators
Vector of factory instances.
Definition: ArenaAllocatorRegistry.cxx:74
SG::ArenaAllocatorRegistryImpl::lock_t
std::lock_guard< std::mutex > lock_t
Definition: ArenaAllocatorRegistry.cxx:79