ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
Control
AthAllocators
src
ArenaAllocatorRegistry.cxx
Go to the documentation of this file.
1
/*
2
Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
3
*/
4
12
13
14
#include "
AthAllocators/ArenaAllocatorRegistry.h
"
15
#include "
AthAllocators/ArenaAllocatorCreator.h
"
16
#include "
AthAllocators/ArenaAllocatorBase.h
"
17
#include "
CxxUtils/checker_macros.h
"
18
#include <vector>
19
#include <map>
20
#include <mutex>
21
#include <cassert>
22
23
24
namespace
SG
{
25
26
30
class
ArenaAllocatorRegistryImpl
31
{
32
public
:
34
~ArenaAllocatorRegistryImpl
();
35
36
47
size_t
registerCreator
(
const
std::string& name,
48
std::unique_ptr<ArenaAllocatorCreator> creator);
49
50
57
size_t
lookup
(
const
std::string& name);
58
59
65
std::unique_ptr<ArenaAllocatorBase>
create
(
size_t
i);
66
67
68
private
:
70
typedef
std::map<std::string, size_t>
map_t
;
71
map_t
m_map
;
72
74
std::vector<std::unique_ptr<ArenaAllocatorCreator> >
m_creators
;
75
77
std::mutex
m_mutex
;
78
79
typedef
std::lock_guard<std::mutex>
lock_t
;
80
};
81
82
86
ArenaAllocatorRegistryImpl::~ArenaAllocatorRegistryImpl
()
87
{
88
}
89
90
101
size_t
102
ArenaAllocatorRegistryImpl::registerCreator
(
const
std::string& name,
103
std::unique_ptr<ArenaAllocatorCreator> creator)
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
}
125
126
133
size_t
ArenaAllocatorRegistryImpl::lookup
(
const
std::string& name)
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
}
142
143
149
std::unique_ptr<ArenaAllocatorBase>
150
ArenaAllocatorRegistryImpl::create
(
size_t
i)
151
{
152
lock_t
lock
(
m_mutex
);
153
assert (i <
m_creators
.size());
154
return
m_creators
[i]->create();
155
}
156
157
158
//==========================================================================
159
170
size_t
171
ArenaAllocatorRegistry::registerCreator
(
const
std::string& name,
172
std::unique_ptr<ArenaAllocatorCreator> creator)
173
{
174
return
m_impl
->registerCreator (name, std::move (creator));
175
}
176
177
184
size_t
ArenaAllocatorRegistry::lookup
(
const
std::string& name)
185
{
186
return
m_impl
->lookup (name);
187
}
188
189
195
std::unique_ptr<ArenaAllocatorBase>
ArenaAllocatorRegistry::create
(
size_t
i)
196
{
197
return
m_impl
->create (i);
198
}
199
200
204
ArenaAllocatorRegistry
*
ArenaAllocatorRegistry::instance
()
205
{
206
static
ArenaAllocatorRegistry
tmp
ATLAS_THREAD_SAFE
;
207
return
&tmp;
208
}
209
210
214
ArenaAllocatorRegistry::ArenaAllocatorRegistry
()
215
:
m_impl
(
std
::make_unique<
ArenaAllocatorRegistryImpl
>())
216
{
217
}
218
219
223
ArenaAllocatorRegistry::~ArenaAllocatorRegistry
()
224
{
225
}
226
227
228
}
// namespace SG
ArenaAllocatorBase.h
Common base class for arena allocator classes. See Arena.h for an overview of the arena-based memory ...
ArenaAllocatorCreator.h
Provide an interface for creating an arena Allocator. See Arena.h for an overview of the arena-based ...
ArenaAllocatorRegistry.h
Registry of allocator factories. See Arena.h for an overview of the arena-based memory allocators.
checker_macros.h
Define macros for attributes used to control the static checker.
ATLAS_THREAD_SAFE
#define ATLAS_THREAD_SAFE
Definition
checker_macros.h:211
SG::ArenaAllocatorRegistryImpl
ArenaAllocatorRegistry implementation class.
Definition
ArenaAllocatorRegistry.cxx:31
SG::ArenaAllocatorRegistryImpl::~ArenaAllocatorRegistryImpl
~ArenaAllocatorRegistryImpl()
Destructor.
Definition
ArenaAllocatorRegistry.cxx:86
SG::ArenaAllocatorRegistryImpl::create
std::unique_ptr< ArenaAllocatorBase > create(size_t i)
Create a new instance of an allocator.
Definition
ArenaAllocatorRegistry.cxx:150
SG::ArenaAllocatorRegistryImpl::map_t
std::map< std::string, size_t > map_t
Map from names to indices.
Definition
ArenaAllocatorRegistry.cxx:70
SG::ArenaAllocatorRegistryImpl::m_map
map_t m_map
Definition
ArenaAllocatorRegistry.cxx:71
SG::ArenaAllocatorRegistryImpl::lookup
size_t lookup(const std::string &name)
Look up the index for an allocator type name.
Definition
ArenaAllocatorRegistry.cxx:133
SG::ArenaAllocatorRegistryImpl::registerCreator
size_t registerCreator(const std::string &name, std::unique_ptr< ArenaAllocatorCreator > creator)
Register a new allocator type.
Definition
ArenaAllocatorRegistry.cxx:102
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
SG::ArenaAllocatorRegistryImpl::m_mutex
std::mutex m_mutex
Mutex to protect the contents.
Definition
ArenaAllocatorRegistry.cxx:77
SG::ArenaAllocatorRegistry::create
std::unique_ptr< ArenaAllocatorBase > create(size_t i)
Create a new instance of an allocator.
Definition
ArenaAllocatorRegistry.cxx:195
SG::ArenaAllocatorRegistry::registerCreator
size_t registerCreator(const std::string &name, std::unique_ptr< ArenaAllocatorCreator > creator)
Register a new allocator type.
Definition
ArenaAllocatorRegistry.cxx:171
SG::ArenaAllocatorRegistry::ArenaAllocatorRegistry
ArenaAllocatorRegistry()
Constructor. Called only by instance.
Definition
ArenaAllocatorRegistry.cxx:214
SG::ArenaAllocatorRegistry::ArenaAllocatorRegistry
ArenaAllocatorRegistry(const ArenaAllocatorRegistry &)
SG::ArenaAllocatorRegistry::lookup
size_t lookup(const std::string &name)
Look up the index for an allocator type name.
Definition
ArenaAllocatorRegistry.cxx:184
SG::ArenaAllocatorRegistry::~ArenaAllocatorRegistry
~ArenaAllocatorRegistry()
Destructor. Called only by instance.
Definition
ArenaAllocatorRegistry.cxx:223
SG::ArenaAllocatorRegistry::ArenaAllocatorRegistryImpl
friend class ArenaAllocatorRegistryImpl
Definition
ArenaAllocatorRegistry.h:98
SG::ArenaAllocatorRegistry::m_impl
std::unique_ptr< ArenaAllocatorRegistryImpl > m_impl
The implementation object.
Definition
ArenaAllocatorRegistry.h:85
SG::ArenaAllocatorRegistry::instance
static ArenaAllocatorRegistry * instance()
Return a pointer to the global ArenaAllocatorRegistry instance.
Definition
ArenaAllocatorRegistry.cxx:204
SG
Forward declaration.
Definition
CaloCellPacker_400_500.h:32
SG::lock
virtual void lock() override
Lock the container.
std
STL namespace.
Generated on
for ATLAS Offline Software by
1.17.0