mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-02-13 05:21:32 -05:00
suppressed potential SIGSEGV as exit time
git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@4068 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
3ae378d9b9
commit
800cc281c5
@ -170,14 +170,21 @@ void FixedAllocator::printStatistics() const
|
|||||||
SmallObjectAllocator::SmallObjectAllocator(size_t maxObjectSize)
|
SmallObjectAllocator::SmallObjectAllocator(size_t maxObjectSize)
|
||||||
: _maxObjectSize(maxObjectSize)
|
: _maxObjectSize(maxObjectSize)
|
||||||
{
|
{
|
||||||
|
RsStackMutex m(SmallObject::_mtx) ;
|
||||||
|
|
||||||
_lastAlloc = NULL ;
|
_lastAlloc = NULL ;
|
||||||
_lastDealloc = NULL ;
|
_lastDealloc = NULL ;
|
||||||
|
_active = true ;
|
||||||
}
|
}
|
||||||
|
|
||||||
SmallObjectAllocator::~SmallObjectAllocator()
|
SmallObjectAllocator::~SmallObjectAllocator()
|
||||||
{
|
{
|
||||||
|
RsStackMutex m(SmallObject::_mtx) ;
|
||||||
|
|
||||||
for(std::map<int,FixedAllocator*>::const_iterator it(_pool.begin());it!=_pool.end();++it)
|
for(std::map<int,FixedAllocator*>::const_iterator it(_pool.begin());it!=_pool.end();++it)
|
||||||
delete it->second ;
|
delete it->second ;
|
||||||
|
|
||||||
|
_active = false ;
|
||||||
}
|
}
|
||||||
|
|
||||||
void *SmallObjectAllocator::allocate(size_t bytes)
|
void *SmallObjectAllocator::allocate(size_t bytes)
|
||||||
@ -255,6 +262,10 @@ void *SmallObject::operator new(size_t size)
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
RsStackMutex m(_mtx) ;
|
RsStackMutex m(_mtx) ;
|
||||||
|
|
||||||
|
if(!_allocator._active)
|
||||||
|
return (void*)NULL;
|
||||||
|
|
||||||
void *p = _allocator.allocate(size) ;
|
void *p = _allocator.allocate(size) ;
|
||||||
#ifdef DEBUG_MEMORY
|
#ifdef DEBUG_MEMORY
|
||||||
std::cerr << "new RsItem: " << p << ", size=" << size << std::endl;
|
std::cerr << "new RsItem: " << p << ", size=" << size << std::endl;
|
||||||
@ -265,6 +276,10 @@ void *SmallObject::operator new(size_t size)
|
|||||||
void SmallObject::operator delete(void *p,size_t size)
|
void SmallObject::operator delete(void *p,size_t size)
|
||||||
{
|
{
|
||||||
RsStackMutex m(_mtx) ;
|
RsStackMutex m(_mtx) ;
|
||||||
|
|
||||||
|
if(!_allocator._active)
|
||||||
|
return ;
|
||||||
|
|
||||||
_allocator.deallocate(p,size) ;
|
_allocator.deallocate(p,size) ;
|
||||||
#ifdef DEBUG_MEMORY
|
#ifdef DEBUG_MEMORY
|
||||||
std::cerr << "del RsItem: " << p << ", size=" << size << std::endl;
|
std::cerr << "del RsItem: " << p << ", size=" << size << std::endl;
|
||||||
@ -274,6 +289,10 @@ void SmallObject::operator delete(void *p,size_t size)
|
|||||||
void SmallObject::printStatistics()
|
void SmallObject::printStatistics()
|
||||||
{
|
{
|
||||||
RsStackMutex m(_mtx) ;
|
RsStackMutex m(_mtx) ;
|
||||||
|
|
||||||
|
if(!_allocator._active)
|
||||||
|
return ;
|
||||||
|
|
||||||
_allocator.printStatistics() ;
|
_allocator.printStatistics() ;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -85,6 +85,8 @@ namespace RsMemoryManagement
|
|||||||
void deallocate(void *p,size_t size) ;
|
void deallocate(void *p,size_t size) ;
|
||||||
|
|
||||||
void printStatistics() const ;
|
void printStatistics() const ;
|
||||||
|
|
||||||
|
bool _active ;
|
||||||
private:
|
private:
|
||||||
std::map<int,FixedAllocator*> _pool ;
|
std::map<int,FixedAllocator*> _pool ;
|
||||||
FixedAllocator *_lastAlloc ;
|
FixedAllocator *_lastAlloc ;
|
||||||
@ -105,6 +107,8 @@ namespace RsMemoryManagement
|
|||||||
private:
|
private:
|
||||||
static SmallObjectAllocator _allocator ;
|
static SmallObjectAllocator _allocator ;
|
||||||
static RsMutex _mtx;
|
static RsMutex _mtx;
|
||||||
|
|
||||||
|
friend class SmallObjectAllocator ;
|
||||||
};
|
};
|
||||||
|
|
||||||
extern void printStatistics() ;
|
extern void printStatistics() ;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user