/* Functions to support a pool of allocatable objects.
- Copyright (C) 1987, 1997, 1998, 1999, 2000, 2001, 2003, 2004, 2005
+ Copyright (C) 1987, 1997, 1998, 1999, 2000, 2001, 2003, 2004, 2005, 2006
Free Software Foundation, Inc.
Contributed by Daniel Berlin <dan@cgsoftware.com>
You should have received a copy of the GNU General Public License
along with GCC; see the file COPYING. If not, write to the Free
-Software Foundation, 59 Temple Place - Suite 330, Boston, MA
-02111-1307, USA. */
+Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301, USA. */
#include "config.h"
#include "system.h"
slot = (struct alloc_pool_descriptor **)
htab_find_slot_with_hash (alloc_pool_hash, name,
- htab_hash_pointer (name),
+ htab_hash_pointer (name),
1);
if (*slot)
return *slot;
free (pool);
}
+/* Frees the alloc_pool, if it is empty and zero *POOL in this case. */
+void
+free_alloc_pool_if_empty (alloc_pool *pool)
+{
+ if ((*pool)->elts_free == (*pool)->elts_allocated)
+ {
+ free_alloc_pool (*pool);
+ *pool = NULL;
+ }
+}
+
/* Allocates one element from the pool specified. */
void *
pool_alloc (alloc_pool pool)
alloc_pool_list block_header;
/* Make the block. */
- block = xmalloc (pool->block_size);
+ block = XNEWVEC (char, pool->block_size);
block_header = (alloc_pool_list) block;
block += align_eight (sizeof (struct alloc_pool_list_def));
#ifdef GATHER_STATISTICS
/* Mark the element to be free. */
((allocation_object *) block)->id = 0;
#endif
- header = (alloc_pool_list) USER_PTR_FROM_ALLOCATION_OBJECT_PTR (block);
- header->next = pool->free_list;
- pool->free_list = header;
+ header = (alloc_pool_list) USER_PTR_FROM_ALLOCATION_OBJECT_PTR (block);
+ header->next = pool->free_list;
+ pool->free_list = header;
}
/* Also update the number of elements we have free/allocated, and
- increment the allocated block count. */
+ increment the allocated block count. */
pool->elts_allocated += pool->elts_per_block;
pool->elts_free += pool->elts_per_block;
pool->blocks_allocated += 1;
gcc_assert (ptr);
#ifdef ENABLE_CHECKING
- memset (ptr, 0xaf, pool->elt_size - offsetof (allocation_object, u.data));
-
/* Check whether the PTR was allocated from POOL. */
gcc_assert (pool->id == ALLOCATION_OBJECT_PTR_FROM_USER_PTR (ptr)->id);
+ memset (ptr, 0xaf, pool->elt_size - offsetof (allocation_object, u.data));
+
/* Mark the element to be free. */
ALLOCATION_OBJECT_PTR_FROM_USER_PTR (ptr)->id = 0;
#else
#endif
/* Output per-alloc_pool memory usage statistics. */
-void dump_alloc_pool_statistics (void)
+void
+dump_alloc_pool_statistics (void)
{
#ifdef GATHER_STATISTICS
struct output_info info;