|
From: <sv...@va...> - 2012-01-18 08:16:53
|
Author: bart Date: 2012-01-18 08:12:16 +0000 (Wed, 18 Jan 2012) New Revision: 12343 Log: 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). Modified: trunk/coregrind/m_oset.c trunk/coregrind/m_poolalloc.c trunk/include/pub_tool_poolalloc.h Modified: trunk/coregrind/m_oset.c =================================================================== --- trunk/coregrind/m_oset.c 2012-01-17 22:27:47 UTC (rev 12342) +++ trunk/coregrind/m_oset.c 2012-01-18 08:12:16 UTC (rev 12343) @@ -377,15 +377,12 @@ 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; Modified: trunk/coregrind/m_poolalloc.c =================================================================== --- trunk/coregrind/m_poolalloc.c 2012-01-17 22:27:47 UTC (rev 12342) +++ trunk/coregrind/m_poolalloc.c 2012-01-18 08:12:16 UTC (rev 12343) @@ -137,14 +137,13 @@ 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; -} - Modified: trunk/include/pub_tool_poolalloc.h =================================================================== --- trunk/include/pub_tool_poolalloc.h 2012-01-17 22:27:47 UTC (rev 12342) +++ trunk/include/pub_tool_poolalloc.h 2012-01-18 08:12:16 UTC (rev 12343) @@ -80,13 +80,11 @@ // 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); +// 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); -// 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); - #endif // __PUB_TOOL_POOLALLOC_ /*--------------------------------------------------------------------*/ |