Make SharedObject members const, the counter mutable

This commit is contained in:
Vinnie Falco
2013-09-12 02:20:13 -07:00
parent 6eda7772eb
commit 9eda4bc6fa
3 changed files with 11 additions and 9 deletions

View File

@@ -87,7 +87,7 @@ protected:
#endif
}
void destroy ()
void destroy () const
{
delete this;
}

View File

@@ -85,11 +85,13 @@ protected:
// the size from the original allocation, which we saved at
// the time of construction.
//
void destroy ()
void destroy () const
{
Handler local (BOOST_ASIO_MOVE_CAST(Handler)(m_handler));
std::size_t const size (m_size);
SharedHandler* const shared (static_cast <SharedHandler*>(this));
SharedHandler* const shared (
const_cast <SharedHandler*> (
static_cast <SharedHandler const*>(this)));
shared->~SharedHandler ();
boost_asio_handler_alloc_helpers::
deallocate <Handler> (shared, size, local);
@@ -109,7 +111,7 @@ protected:
protected:
std::size_t const m_size;
Handler m_handler;
Handler mutable m_handler;
};
//--------------------------------------------------------------------------

View File

@@ -65,7 +65,7 @@ public:
This is done automatically by the smart pointer, but is public just
in case it's needed for nefarious purposes.
*/
inline void incReferenceCount() noexcept
inline void incReferenceCount() const noexcept
{
++refCount;
}
@@ -79,7 +79,7 @@ public:
The return value indicates if the reference count dropped to zero,
so callers who know the derived type can use the ContainerDeletePolicy.
*/
void decReferenceCount ()
void decReferenceCount () const
{
bassert (getReferenceCount() > 0);
if (--refCount == 0)
@@ -109,7 +109,7 @@ protected:
/** Destroy the object.
Derived classes can override this for different behaviors.
*/
virtual void destroy ()
virtual void destroy () const
{
delete this;
}
@@ -124,7 +124,7 @@ protected:
private:
//==============================================================================
Atomic <int> refCount;
Atomic <int> mutable refCount;
};
//==============================================================================
@@ -184,7 +184,7 @@ protected:
bassert (getReferenceCount() == 0);
}
virtual void destroy ()
virtual void destroy () const
{
delete this;
}