// --------------------------------------------------------------
-// We rely on this array of pointers being zeroed when the process
-// starts *before* the ctors from *any* linked modules are executed.
-// That way, regardless of link order, pool_t's are allocated and
-// instantiated on demand.
-static mempool::pool_t *pools[mempool::num_pools];
-
mempool::pool_t& mempool::get_pool(mempool::pool_index_t ix)
{
- if (pools[ix]) {
- return *pools[ix];
- }
+ // We rely on this array being initialized before any invocation of
+ // this function, even if it is called by ctors in other compilation
+ // units that are being initialized before this compilation unit.
+ static mempool::pool_t table[num_pools];
+ return table[ix];
+}
- switch (ix) {
-#define P(x) \
- case mempool_##x: pools[ix] = new mempool::pool_t(#x); break;
- DEFINE_MEMORY_POOLS_HELPER(P);
+const char *mempool::get_pool_name(mempool::pool_index_t ix) {
+#define P(x) #x,
+ static const char *names[num_pools] = {
+ DEFINE_MEMORY_POOLS_HELPER(P)
+ };
#undef P
- default: assert(0);
- }
- return *pools[ix];
+ return names[ix];
}
void mempool::dump(ceph::Formatter *f, size_t skip)
{
for (size_t i = skip; i < num_pools; ++i) {
- if (!pools[i])
- continue;
const pool_t &pool = mempool::get_pool((pool_index_t)i);
- f->open_object_section(pool.get_name().c_str());
+ f->open_object_section(get_pool_name((pool_index_t)i));
pool.dump(f);
f->close_section();
}
};
pool_t& get_pool(pool_index_t ix);
+const char *get_pool_name(pool_index_t ix);
struct type_t {
const char *type_name;
};
class pool_t {
- std::string name;
shard_t shard[num_shards];
mutable std::mutex lock; // only used for types list
std::unordered_map<const char *, type_t> type_map;
public:
- pool_t(const std::string& n)
- : name(n) {
- }
-
//
// How much this pool consumes. O(<num_shards>)
//
size_t allocated_bytes() const;
size_t allocated_items() const;
- const std::string& get_name() const {
- return name;
- }
-
shard_t* pick_a_shard() {
// Dirt cheap, see:
// http://fossies.org/dox/glibc-2.24/pthread__self_8c_source.html