Commit 431e6b59 authored by Samuel Debionne's avatar Samuel Debionne

Do not destroy default Allocator until it's empty

parent 4c951208
......@@ -59,13 +59,6 @@ struct LIMACORE_API Allocator
"Moved-from Allocator is not empty");
}
~Allocator()
{
if (m_ref_count != 0)
std::cerr << "Error: destroying non-empty Allocator"
<< std::endl;
}
// Allocate a buffer of a given size and eventually return
// the associated allocator data and potentially modified size
virtual DataPtr alloc(void* &ptr, size_t& size, size_t alignment = 16);
......@@ -107,11 +100,18 @@ struct LIMACORE_API Allocator
protected:
friend class Ref;
virtual ~Allocator()
{
if (m_ref_count != 0)
std::cerr << "Error: destroying non-empty Allocator"
<< std::endl;
}
// The real resource management counter, triggered by Ref
Allocator *get()
{ return ++m_ref_count, this; }
void put()
{ --m_ref_count; }
{ if (--m_ref_count == 0) delete this; }
// Keep track of allocated buffers pointing to this Allocator:
// if greather than 0 this object cannot be moved
......
......@@ -108,8 +108,8 @@ void lima::ClearBuffer(void *ptr, int nb_concat_frames,
Allocator *Allocator::defaultAllocator()
{
static Allocator allocator;
return &allocator;
static Allocator::Ref allocator = new Allocator();
return allocator;
}
Allocator::DataPtr Allocator::alloc(void* &ptr, size_t& size, size_t alignment)
......
......@@ -97,7 +97,7 @@ class LIMACORE_API SoftBufferAllocMgr : public BufferAllocMgr
typedef BufferList::const_reverse_iterator BufferListCRIt;
FrameDim m_frame_dim;
Allocator *m_allocator;
Allocator::Ref m_allocator;
BufferList m_buffer_list;
};
......@@ -116,7 +116,7 @@ class LIMACORE_API NumaSoftBufferAllocMgr : public SoftBufferAllocMgr
void setCPUAffinityMask(unsigned long mask);
protected:
AutoPtr<NumaAllocator> m_numa_allocator;
NumaAllocator *m_numa_allocator;
};
#endif //LIMA_USE_NUMA
......
......@@ -60,9 +60,9 @@ void BufferAllocMgr::clearAllBuffers()
*******************************************************************/
SoftBufferAllocMgr::SoftBufferAllocMgr()
: m_allocator(Allocator::defaultAllocator())
{
DEB_CONSTRUCTOR();
setAllocator(Allocator::defaultAllocator());
}
SoftBufferAllocMgr::~SoftBufferAllocMgr()
......@@ -169,6 +169,7 @@ void *SoftBufferAllocMgr::getBufferPtr(int buffer_nb)
#ifdef LIMA_USE_NUMA
NumaSoftBufferAllocMgr::NumaSoftBufferAllocMgr()
: m_numa_allocator(NULL)
{
DEB_CONSTRUCTOR();
setCPUAffinityMask(0);
......
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