Kaydet (Commit) 2950528c authored tarafından Stephan Bergmann's avatar Stephan Bergmann

No need for rtl_cache_* here

...which shows that m_pCount will never be null

Change-Id: I87c6e4bf5d258c59a8e91cd194c64b1ce85b4445
üst 673fe197
......@@ -31,39 +31,6 @@
using namespace store;
/*========================================================================
*
* SharedCount::Allocator.
*
*======================================================================*/
SharedCount::Allocator &
SharedCount::Allocator::get()
{
static Allocator g_aSharedCountAllocator;
return g_aSharedCountAllocator;
}
SharedCount::Allocator::Allocator()
{
m_cache = rtl_cache_create (
"store_shared_count_cache",
sizeof(long),
0, // objalign
nullptr, // constructor
nullptr, // destructor
nullptr, // reclaim
nullptr, // userarg
nullptr, // default source
0 // flags
);
}
SharedCount::Allocator::~Allocator()
{
rtl_cache_destroy (m_cache);
m_cache = nullptr;
}
/*========================================================================
*
* PageData::Allocator_Impl (default allocator).
......
......@@ -84,42 +84,18 @@ class SharedCount
{
long * m_pCount;
class Allocator
{
rtl_cache_type * m_cache;
public:
static Allocator & get();
long * alloc()
{
return static_cast<long*>(rtl_cache_alloc (m_cache));
}
void free (long * pCount)
{
rtl_cache_free (m_cache, pCount);
}
protected:
Allocator();
~Allocator();
};
public:
SharedCount()
: m_pCount(Allocator::get().alloc())
: m_pCount(new long)
{
if (m_pCount != nullptr) (*m_pCount) = 1;
(*m_pCount) = 1;
}
~SharedCount()
{
if (m_pCount != nullptr)
{
long new_count = --(*m_pCount);
if (new_count == 0)
Allocator::get().free(m_pCount);
}
long new_count = --(*m_pCount);
if (new_count == 0)
delete m_pCount;
}
void swap (SharedCount & rhs) // nothrow
......@@ -130,7 +106,7 @@ public:
SharedCount (SharedCount const & rhs) // nothrow
: m_pCount (rhs.m_pCount)
{
if (m_pCount != nullptr) ++(*m_pCount);
++(*m_pCount);
}
SharedCount & operator= (SharedCount const & rhs) // nothrow
{
......@@ -141,7 +117,7 @@ public:
bool operator== (long count) const
{
return (m_pCount != nullptr) && (*m_pCount == count);
return *m_pCount == count;
}
};
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment