-/* -*- mode: C; c-file-style: "gnu" -*- */
+/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
/* dbus-mempool.h Memory pools
*
* Copyright (C) 2002, 2003 Red Hat, Inc.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
*/
+#include <config.h>
#include "dbus-mempool.h"
#include "dbus-internals.h"
+#include "dbus-valgrind-internal.h"
/**
* @defgroup DBusMemPool memory pools
_dbus_assert ((pool->block_size %
pool->element_size) == 0);
-
+
+ VALGRIND_CREATE_MEMPOOL (pool, 0, zero_elements);
+
return pool;
}
{
DBusMemBlock *block;
+ VALGRIND_DESTROY_MEMPOOL (pool);
+
block = pool->blocks;
while (block != NULL)
{
pool->blocks = block;
pool->allocated_elements += 1;
+ VALGRIND_MEMPOOL_ALLOC (pool, (void *) &block->elements[0],
+ pool->element_size);
return (void*) &block->elements[0];
}
else
pool->free_elements = pool->free_elements->next;
+ VALGRIND_MEMPOOL_ALLOC (pool, element, pool->element_size);
+
if (pool->zero_elements)
memset (element, '\0', pool->element_size);
pool->allocated_elements += 1;
-
+
return element;
}
else
pool->blocks->used_so_far += pool->element_size;
pool->allocated_elements += 1;
-
+
+ VALGRIND_MEMPOOL_ALLOC (pool, element, pool->element_size);
return element;
}
}
_dbus_mem_pool_dealloc (DBusMemPool *pool,
void *element)
{
+ VALGRIND_MEMPOOL_FREE (pool, element);
+
#ifdef DBUS_BUILD_TESTS
if (_dbus_disable_mem_pools ())
{
DBusFreedElement *freed;
freed = element;
+ /* used for internal mempool administration */
+ VALGRIND_MAKE_MEM_UNDEFINED (freed, sizeof (freed));
+
freed->next = pool->free_elements;
pool->free_elements = freed;
}
}
+#ifdef DBUS_ENABLE_STATS
+void
+_dbus_mem_pool_get_stats (DBusMemPool *pool,
+ dbus_uint32_t *in_use_p,
+ dbus_uint32_t *in_free_list_p,
+ dbus_uint32_t *allocated_p)
+{
+ DBusMemBlock *block;
+ DBusFreedElement *freed;
+ dbus_uint32_t in_use = 0;
+ dbus_uint32_t in_free_list = 0;
+ dbus_uint32_t allocated = 0;
+
+ if (pool != NULL)
+ {
+ in_use = pool->element_size * pool->allocated_elements;
+
+ for (freed = pool->free_elements; freed != NULL; freed = freed->next)
+ {
+ in_free_list += pool->element_size;
+ }
+
+ for (block = pool->blocks; block != NULL; block = block->next)
+ {
+ if (block == pool->blocks)
+ allocated += pool->block_size;
+ else
+ allocated += block->used_so_far;
+ }
+ }
+
+ if (in_use_p != NULL)
+ *in_use_p = in_use;
+
+ if (in_free_list_p != NULL)
+ *in_free_list_p = in_free_list;
+
+ if (allocated_p != NULL)
+ *allocated_p = allocated;
+}
+#endif /* DBUS_ENABLE_STATS */
+
/** @} */
#ifdef DBUS_BUILD_TESTS