27#include "dbus-mempool.h"
28#include "dbus-internals.h"
29#include "dbus-valgrind-internal.h"
72#define ELEMENT_PADDING 4
150 if (element_size < 8)
162 pool->
element_size = _DBUS_ALIGN_VALUE (element_size,
sizeof (
void *));
178 VALGRIND_CREATE_MEMPOOL (pool, 0, zero_elements);
193 VALGRIND_DESTROY_MEMPOOL (pool);
196 while (block !=
NULL)
218#ifdef DBUS_ENABLE_EMBEDDED_TESTS
219 if (_dbus_disable_mem_pools ())
245 VALGRIND_MEMPOOL_ALLOC (pool, (
void *) &block->
elements[0],
255 if (_dbus_decrement_fail_alloc_counter ())
257 _dbus_verbose (
" FAILING mempool alloc\n");
266 VALGRIND_MEMPOOL_ALLOC (pool, element, pool->
element_size);
285#ifdef DBUS_ENABLE_EMBEDDED_TESTS
299#ifdef DBUS_ENABLE_EMBEDDED_TESTS
306 saved_counter = _dbus_get_fail_alloc_counter ();
315#ifdef DBUS_ENABLE_EMBEDDED_TESTS
316 _dbus_set_fail_alloc_counter (saved_counter);
317 _dbus_assert (saved_counter == _dbus_get_fail_alloc_counter ());
334 VALGRIND_MEMPOOL_ALLOC (pool, element, pool->
element_size);
352 VALGRIND_MEMPOOL_FREE (pool, element);
354#ifdef DBUS_ENABLE_EMBEDDED_TESTS
355 if (_dbus_disable_mem_pools ())
365 while (block !=
NULL)
367 if (block->
elements == (
unsigned char*) element)
398 VALGRIND_MAKE_MEM_UNDEFINED (freed,
sizeof (*freed));
410#ifdef DBUS_ENABLE_STATS
413 dbus_uint32_t *in_use_p,
414 dbus_uint32_t *in_free_list_p,
415 dbus_uint32_t *allocated_p)
419 dbus_uint32_t in_use = 0;
420 dbus_uint32_t in_free_list = 0;
421 dbus_uint32_t allocated = 0;
434 if (block == pool->
blocks)
441 if (in_use_p !=
NULL)
444 if (in_free_list_p !=
NULL)
445 *in_free_list_p = in_free_list;
447 if (allocated_p !=
NULL)
448 *allocated_p = allocated;
#define _dbus_assert_not_reached(explanation)
Aborts with an error message if called.
#define _dbus_assert(condition)
Aborts with an error message if the condition is false.
#define _DBUS_INT_MAX
Maximum value of type "int".
#define NULL
A null pointer, defined appropriately for C or C++.
#define FALSE
Expands to "0".
#define ELEMENT_PADDING
The dummy size of the variable-length "elements" field in DBusMemBlock.
struct DBusMemBlock DBusMemBlock
Typedef for DBusMemBlock so the struct can recursively point to itself.
void * _dbus_mem_pool_alloc(DBusMemPool *pool)
Allocates an object from the memory pool.
dbus_bool_t _dbus_mem_pool_dealloc(DBusMemPool *pool, void *element)
Deallocates an object previously created with _dbus_mem_pool_alloc().
void _dbus_mem_pool_free(DBusMemPool *pool)
Frees a memory pool (and all elements allocated from it).
DBusMemPool * _dbus_mem_pool_new(int element_size, dbus_bool_t zero_elements)
Creates a new memory pool, or returns NULL on failure.
void dbus_free(void *memory)
Frees a block of memory previously allocated by dbus_malloc() or dbus_malloc0().
void * dbus_malloc0(size_t bytes)
Allocates the given number of bytes, as with standard malloc(), but all bytes are initialized to zero...
#define dbus_new0(type, count)
Safe macro for using dbus_malloc0().
void * dbus_malloc(size_t bytes)
Allocates the given number of bytes, as with standard malloc().
dbus_uint32_t dbus_bool_t
A boolean, valid values are TRUE and FALSE.
struct representing an element on the free list.
DBusFreedElement * next
next element of the free list
DBusMemBlock object represents a single malloc()-returned block that gets chunked up into objects in ...
DBusMemBlock * next
next block in the list, which is already used up; only saved so we can free all the blocks when we fr...
long used_so_far
bytes of this block already allocated as elements.
unsigned char elements[ELEMENT_PADDING]
the block data, actually allocated to required size
Internals fields of DBusMemPool.
int allocated_elements
Count of outstanding allocated elements.
unsigned int zero_elements
whether to zero-init allocated elements
int block_size
size of most recently allocated block
DBusMemBlock * blocks
blocks of memory from malloc()
int element_size
size of a single object in the pool
DBusFreedElement * free_elements
a free list of elements to recycle