| 24 | namespace BinaryNinjaDebuggerAPI { |
| 25 | template <class T> |
| 26 | class DbgRefCountObject |
| 27 | { |
| 28 | void AddRefInternal() { m_refs.fetch_add(1); } |
| 29 | |
| 30 | void ReleaseInternal() |
| 31 | { |
| 32 | if (m_refs.fetch_sub(1) == 1) |
| 33 | delete this; |
| 34 | } |
| 35 | |
| 36 | public: |
| 37 | std::atomic<int> m_refs; |
| 38 | T* m_object; |
| 39 | DbgRefCountObject() : m_refs(0), m_object(nullptr) {} |
| 40 | virtual ~DbgRefCountObject() {} |
| 41 | |
| 42 | T* GetObject() const { return m_object; } |
| 43 | |
| 44 | static T* GetObject(DbgRefCountObject* obj) |
| 45 | { |
| 46 | if (!obj) |
| 47 | return nullptr; |
| 48 | return obj->GetObject(); |
| 49 | } |
| 50 | |
| 51 | void AddRef() { AddRefInternal(); } |
| 52 | |
| 53 | void Release() { ReleaseInternal(); } |
| 54 | |
| 55 | void AddRefForRegistration() { AddRefInternal(); } |
| 56 | }; |
| 57 | |
| 58 | |
| 59 | template <class T, T* (*AddObjectReference)(T*), void (*FreeObjectReference)(T*)> |
nothing calls this directly
no outgoing calls
no test coverage detected