This commit is contained in:
Aria 2025-03-21 22:23:30 +11:00
commit 9c94d113d3
Signed by untrusted user who does not match committer: aria
GPG key ID: 19AB7AA462B8AB3B
10260 changed files with 1237388 additions and 0 deletions

View file

@ -0,0 +1,54 @@
#ifndef STAR_LIVE_COUNTER_HPP
#define STAR_LIVE_COUNTER_HPP
#include "StarConfig.hpp"
#include <typeindex>
namespace Star {
typedef atomic<int64_t> LiveAtomicCounter;
void bindLiveCounter(std::type_index const& typeIndex, LiveAtomicCounter*& counter);
void dumpLiveCounters();
// Use as class MyClass : LiveCounter<MyClass> { ... }
template<typename T>
class LiveCounter {
public:
#ifdef STAR_ENABLE_LIVECOUNTER
LiveCounter() {
bindLiveCounter(typeid(T), s_liveCounter);
++(*s_liveCounter);
}
LiveCounter(LiveCounter const&) {
bindLiveCounter(typeid(T), s_liveCounter);
++(*s_liveCounter);
}
LiveCounter(LiveCounter&&) {
bindLiveCounter(typeid(T), s_liveCounter);
++(*s_liveCounter);
}
void operator=(LiveCounter const&) {}
void operator=(LiveCounter&&) {}
~LiveCounter() {
--(*s_liveCounter);
}
private:
static LiveAtomicCounter* s_liveCounter;
#endif
};
#ifdef STAR_ENABLE_LIVECOUNTER
template<typename T>
LiveAtomicCounter* LiveCounter<T>::s_liveCounter = nullptr;
#endif
}
#endif