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

ArenaAllocatorRegistry implementation class. More...

Collaboration diagram for SG::ArenaAllocatorRegistryImpl:

Public Member Functions

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

Private Types

typedef std::map< std::string, size_t > map_t
 Map from names to indices.
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.
std::mutex m_mutex
 Mutex to protect the contents.

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}
std::vector< std::unique_ptr< ArenaAllocatorCreator > > m_creators
Vector of factory instances.
std::lock_guard< std::mutex > lock_t
std::mutex m_mutex
Mutex to protect the contents.

◆ 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: