25 #include "dbus-mempool.h"
26 #include "dbus-internals.h"
27 #include "dbus-valgrind-internal.h"
70 #define ELEMENT_PADDING 4
148 if (element_size < 8)
160 pool->
element_size = _DBUS_ALIGN_VALUE (element_size,
sizeof (
void *));
176 VALGRIND_CREATE_MEMPOOL (pool, 0, zero_elements);
191 VALGRIND_DESTROY_MEMPOOL (pool);
194 while (block !=
NULL)
216 #ifdef DBUS_ENABLE_EMBEDDED_TESTS
217 if (_dbus_disable_mem_pools ())
243 VALGRIND_MEMPOOL_ALLOC (pool, (
void *) &block->
elements[0],
253 if (_dbus_decrement_fail_alloc_counter ())
255 _dbus_verbose (
" FAILING mempool alloc\n");
264 VALGRIND_MEMPOOL_ALLOC (pool, element, pool->
element_size);
283 #ifdef DBUS_ENABLE_EMBEDDED_TESTS
297 #ifdef DBUS_ENABLE_EMBEDDED_TESTS
304 saved_counter = _dbus_get_fail_alloc_counter ();
313 #ifdef DBUS_ENABLE_EMBEDDED_TESTS
314 _dbus_set_fail_alloc_counter (saved_counter);
315 _dbus_assert (saved_counter == _dbus_get_fail_alloc_counter ());
332 VALGRIND_MEMPOOL_ALLOC (pool, element, pool->
element_size);
350 VALGRIND_MEMPOOL_FREE (pool, element);
352 #ifdef DBUS_ENABLE_EMBEDDED_TESTS
353 if (_dbus_disable_mem_pools ())
363 while (block !=
NULL)
365 if (block->
elements == (
unsigned char*) element)
396 VALGRIND_MAKE_MEM_UNDEFINED (freed,
sizeof (*freed));
408 #ifdef DBUS_ENABLE_STATS
432 if (block == pool->
blocks)
439 if (in_use_p !=
NULL)
442 if (in_free_list_p !=
NULL)
443 *in_free_list_p = in_free_list;
445 if (allocated_p !=
NULL)
446 *allocated_p = allocated;
452 #ifdef DBUS_ENABLE_EMBEDDED_TESTS
453 #include "dbus-test.h"
458 time_for_size (
int size)
462 #ifdef DBUS_ENABLE_VERBOSE_MODE
466 #define FREE_ARRAY_SIZE 512
467 #define N_ITERATIONS FREE_ARRAY_SIZE * 512
468 void *to_free[FREE_ARRAY_SIZE];
471 _dbus_verbose (
"Timings for size %d\n", size);
473 _dbus_verbose (
" malloc\n");
475 #ifdef DBUS_ENABLE_VERBOSE_MODE
481 while (i < N_ITERATIONS)
488 if (j == FREE_ARRAY_SIZE)
491 while (j < FREE_ARRAY_SIZE)
503 #ifdef DBUS_ENABLE_VERBOSE_MODE
506 _dbus_verbose (
" created/destroyed %d elements in %g seconds\n",
507 N_ITERATIONS, (end - start) / (
double) CLOCKS_PER_SEC);
511 _dbus_verbose (
" mempools\n");
520 while (i < N_ITERATIONS)
527 if (j == FREE_ARRAY_SIZE)
530 while (j < FREE_ARRAY_SIZE)
544 #ifdef DBUS_ENABLE_VERBOSE_MODE
547 _dbus_verbose (
" created/destroyed %d elements in %g seconds\n",
548 N_ITERATIONS, (end - start) / (
double) CLOCKS_PER_SEC);
550 _dbus_verbose (
" zeroed malloc\n");
557 while (i < N_ITERATIONS)
564 if (j == FREE_ARRAY_SIZE)
567 while (j < FREE_ARRAY_SIZE)
579 #ifdef DBUS_ENABLE_VERBOSE_MODE
582 _dbus_verbose (
" created/destroyed %d elements in %g seconds\n",
583 N_ITERATIONS, (end - start) / (
double) CLOCKS_PER_SEC);
585 _dbus_verbose (
" zeroed mempools\n");
594 while (i < N_ITERATIONS)
601 if (j == FREE_ARRAY_SIZE)
604 while (j < FREE_ARRAY_SIZE)
618 #ifdef DBUS_ENABLE_VERBOSE_MODE
621 _dbus_verbose (
" created/destroyed %d elements in %g seconds\n",
622 N_ITERATIONS, (end - start) / (
double) CLOCKS_PER_SEC);
632 _dbus_mem_pool_test (
void)
635 int element_sizes[] = { 4, 8, 16, 50, 124 };
640 time_for_size (element_sizes[i]);