Skip to content
Snippets Groups Projects
Commit a4361c53 authored by Joseph Boudreau's avatar Joseph Boudreau
Browse files

Merge branch 'InlineRCBase' into 'main'

RCBase - Inline increment decrement, delete copy constructors etc.

See merge request !225
parents 818df80e cd95f2c9
No related branches found
No related tags found
1 merge request!225RCBase - Inline increment decrement, delete copy constructors etc.
Pipeline #6587194 passed
......@@ -21,30 +21,35 @@
#include <atomic>
class RCBase
{
class RCBase {
public:
RCBase();
RCBase() = default;
// Increase the reference count
void ref () const;
void ref() const {
++m_count;
}
// Decreases the reference count. When the reference count
// falls to zero, the object deletes itself.
void unref () const;
void unref () const {
if (--m_count == 0) delete this;
}
// Return the reference count.
unsigned int refCount () const;
unsigned int refCount () const {
return m_count.load();
}
protected:
virtual ~RCBase();
virtual ~RCBase() = default;
private:
RCBase(const RCBase &right);
RCBase & operator=(const RCBase &right);
RCBase(const RCBase &right) = delete;
RCBase & operator=(const RCBase &right) = delete;
// The reference count
mutable std::atomic<unsigned> m_count;
// The reference count
mutable std::atomic<unsigned> m_count{0};
};
......
/*
Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
*/
#include "GeoModelKernel/RCBase.h"
#include <exception>
RCBase::RCBase()
: m_count(0)
{
}
RCBase::~RCBase()
{
}
void RCBase::ref () const
{
m_count++;
}
void RCBase::unref () const
{
if (--m_count == 0) delete this;
}
unsigned int RCBase::refCount () const
{
return m_count.load();
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment