Pool allocator: change the semantics of VG_(releasePA)() according to comment http://bugs.kde.org/show_bug.cgi?id=282230#c50.

This change also makes the semantics of releasePA match the semantics of
other release functions, e.g. those in XPCOM (see also http://developer.mozilla.org/en/XPCOM_Interface_Reference/nsISupports#Release%28%29).


git-svn-id: svn://svn.valgrind.org/valgrind/trunk@12343
This commit is contained in:
Bart Van Assche 2012-01-18 08:12:16 +00:00
parent 4ea8a59e63
commit deb44ff6f0
3 changed files with 17 additions and 23 deletions

View File

@ -377,15 +377,12 @@ void VG_(OSetGen_Destroy)(AvlTree* t)
has_node_pa = t->node_pa != NULL;
if (has_node_pa)
VG_(releasePA) (t->node_pa); // decrement ref count.
if (has_node_pa && VG_(nrRefPA) (t->node_pa) == 0) {
/* We are the only remaining user of this pool allocator.
=> release (more efficiently) all the elements
by deleting the pool allocator */
VG_(deletePA) (t->node_pa);
} else {
/*
* If we are the only remaining user of this pool allocator, release all
* the elements by deleting the pool allocator. That's more efficient than
* deleting tree nodes one by one.
*/
if (!has_node_pa || VG_(releasePA)(t->node_pa) > 0) {
AvlNode* n = NULL;
Int i = 0;
Word sz = 0;

View File

@ -137,14 +137,13 @@ void VG_(addRefPA) ( PoolAlloc* pa)
pa->nrRef++;
}
void VG_(releasePA) ( PoolAlloc* pa)
UWord VG_(releasePA)(PoolAlloc* pa)
{
UWord nrRef;
vg_assert(pa->nrRef > 0);
pa->nrRef--;
nrRef = --pa->nrRef;
if (nrRef == 0)
VG_(deletePA)(pa);
return nrRef;
}
UWord VG_(nrRefPA) (PoolAlloc* pa)
{
return pa->nrRef;
}

View File

@ -80,12 +80,10 @@ extern void VG_(freeEltPA) ( PoolAlloc* pa, void* p);
// VG_(addRefPA) indicates there is a new reference to pa.
extern void VG_(addRefPA) ( PoolAlloc* pa);
// VG_(releasePA) indicates a reference to pa has been released.
extern void VG_(releasePA) ( PoolAlloc* pa);
// Returns the current nr of reference to pa.
// When this drops to 0, VG_(deletePA) can be called by the pa user.
extern UWord VG_(nrRefPA) (PoolAlloc* pa);
// VG_(releasePA) decrements the pa reference count and deletes the pa if that
// reference count has dropped to zero. Returns the new value of the reference
// count.
extern UWord VG_(releasePA) ( PoolAlloc* pa);
#endif // __PUB_TOOL_POOLALLOC_