Coverage report for dbus/dbus-mempool.c.gcov

        -:    0:Source:dbus-mempool.c
        -:    0:Graph:.libs/dbus-mempool.gcno
        -:    0:Data:.libs/dbus-mempool.gcda
        -:    0:Runs:11815
        -:    0:Programs:5
        -:    1:/* -*- mode: C; c-file-style: "gnu" -*- */
        -:    2:/* dbus-mempool.h Memory pools
        -:    3: * 
        -:    4: * Copyright (C) 2002, 2003  Red Hat, Inc.
        -:    5: *
        -:    6: * Licensed under the Academic Free License version 2.1
        -:    7: * 
        -:    8: * This program is free software; you can redistribute it and/or modify
        -:    9: * it under the terms of the GNU General Public License as published by
        -:   10: * the Free Software Foundation; either version 2 of the License, or
        -:   11: * (at your option) any later version.
        -:   12: *
        -:   13: * This program is distributed in the hope that it will be useful,
        -:   14: * but WITHOUT ANY WARRANTY; without even the implied warranty of
        -:   15: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
        -:   16: * GNU General Public License for more details.
        -:   17: * 
        -:   18: * You should have received a copy of the GNU General Public License
        -:   19: * along with this program; if not, write to the Free Software
        -:   20: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
        -:   21: *
        -:   22: */
        -:   23:
        -:   24:#include "dbus-mempool.h"
        -:   25:#include "dbus-internals.h"
        -:   26:
        -:   27:/**
        -:   28: * @defgroup DBusMemPool memory pools
        -:   29: * @ingroup  DBusInternals
        -:   30: * @brief DBusMemPool object
        -:   31: *
        -:   32: * Types and functions related to DBusMemPool.  A memory pool is used
        -:   33: * to decrease memory fragmentation/overhead and increase speed for
        -:   34: * blocks of small uniformly-sized objects. The main point is to avoid
        -:   35: * the overhead of a malloc block for each small object, speed is
        -:   36: * secondary.
        -:   37: */
        -:   38:
        -:   39:/**
        -:   40: * @defgroup DBusMemPoolInternals Memory pool implementation details
        -:   41: * @ingroup  DBusInternals
        -:   42: * @brief DBusMemPool implementation details
        -:   43: *
        -:   44: * The guts of DBusMemPool.
        -:   45: *
        -:   46: * @{
        -:   47: */
        -:   48:
        -:   49:/**
        -:   50: * typedef so DBusFreedElement struct can refer to itself.
        -:   51: */
        -:   52:typedef struct DBusFreedElement DBusFreedElement;
        -:   53:
        -:   54:/**
        -:   55: * struct representing an element on the free list.
        -:   56: * We just cast freed elements to this so we can
        -:   57: * make a list out of them.
        -:   58: */
        -:   59:struct DBusFreedElement
        -:   60:{
        -:   61:  DBusFreedElement *next; /**< next element of the free list */
        -:   62:};
        -:   63:
        -:   64:/**
        -:   65: * The dummy size of the variable-length "elements"
        -:   66: * field in DBusMemBlock
        -:   67: */
        -:   68:#define ELEMENT_PADDING 4
        -:   69:
        -:   70:/**
        -:   71: * Typedef for DBusMemBlock so the struct can recursively
        -:   72: * point to itself.
        -:   73: */
        -:   74:typedef struct DBusMemBlock DBusMemBlock;
        -:   75:
        -:   76:/**
        -:   77: * DBusMemBlock object represents a single malloc()-returned
        -:   78: * block that gets chunked up into objects in the memory pool.
        -:   79: */
        -:   80:struct DBusMemBlock
        -:   81:{
        -:   82:  DBusMemBlock *next;  /**< next block in the list, which is already used up;
        -:   83:                        *   only saved so we can free all the blocks
        -:   84:                        *   when we free the mem pool.
        -:   85:                        */
        -:   86:
        -:   87:  /* this is a long so that "elements" is aligned */
        -:   88:  long used_so_far;     /**< bytes of this block already allocated as elements. */
        -:   89:  
        -:   90:  unsigned char elements[ELEMENT_PADDING]; /**< the block data, actually allocated to required size */
        -:   91:};
        -:   92:
        -:   93:/**
        -:   94: * Internals fields of DBusMemPool
        -:   95: */
        -:   96:struct DBusMemPool
        -:   97:{
        -:   98:  int element_size;                /**< size of a single object in the pool */
        -:   99:  int block_size;                  /**< size of most recently allocated block */
        -:  100:  unsigned int zero_elements : 1;  /**< whether to zero-init allocated elements */
        -:  101:
        -:  102:  DBusFreedElement *free_elements; /**< a free list of elements to recycle */
        -:  103:  DBusMemBlock *blocks;            /**< blocks of memory from malloc() */
        -:  104:  int allocated_elements;          /**< Count of outstanding allocated elements */
        -:  105:};
        -:  106:
        -:  107:/** @} */
        -:  108:
        -:  109:/**
        -:  110: * @addtogroup DBusMemPool
        -:  111: *
        -:  112: * @{
        -:  113: */
        -:  114:
        -:  115:/**
        -:  116: * @typedef DBusMemPool
        -:  117: *
        -:  118: * Opaque object representing a memory pool. Memory pools allow
        -:  119: * avoiding per-malloc-block memory overhead when allocating a lot of
        -:  120: * small objects that are all the same size. They are slightly
        -:  121: * faster than calling malloc() also.
        -:  122: */
        -:  123:
        -:  124:/**
        -:  125: * Creates a new memory pool, or returns #NULL on failure.  Objects in
        -:  126: * the pool must be at least sizeof(void*) bytes each, due to the way
        -:  127: * memory pools work. To avoid creating 64 bit problems, this means at
        -:  128: * least 8 bytes on all platforms, unless you are 4 bytes on 32-bit
        -:  129: * and 8 bytes on 64-bit.
        -:  130: *
        -:  131: * @param element_size size of an element allocated from the pool.
        -:  132: * @param zero_elements whether to zero-initialize elements
        -:  133: * @returns the new pool or #NULL
        -:  134: */
        -:  135:DBusMemPool*
        -:  136:_dbus_mem_pool_new (int element_size,
        -:  137:                    dbus_bool_t zero_elements)
function _dbus_mem_pool_new called 1479027 returned 100% blocks executed 100%
  1479027:  138:{
        -:  139:  DBusMemPool *pool;
        -:  140:
  1479027:  141:  pool = dbus_new0 (DBusMemPool, 1);
call    0 returned 100%
  1479027:  142:  if (pool == NULL)
branch  0 taken 1% (fallthrough)
branch  1 taken 99%
       36:  143:    return NULL;
        -:  144:
        -:  145:  /* Make the element size at least 8 bytes. */
  1478991:  146:  if (element_size < 8)
branch  0 taken 1% (fallthrough)
branch  1 taken 99%
        2:  147:    element_size = 8;
        -:  148:  
        -:  149:  /* these assertions are equivalent but the first is more clear
        -:  150:   * to programmers that see it fail.
        -:  151:   */
  1478991:  152:  _dbus_assert (element_size >= (int) sizeof (void*));
call    0 returned 100%
  1478991:  153:  _dbus_assert (element_size >= (int) sizeof (DBusFreedElement));
call    0 returned 100%
        -:  154:
        -:  155:  /* align the element size to a pointer boundary so we won't get bus
        -:  156:   * errors under other architectures.  
        -:  157:   */
  1478991:  158:  pool->element_size = _DBUS_ALIGN_VALUE (element_size, sizeof (void *));
        -:  159:
  1478991:  160:  pool->zero_elements = zero_elements != FALSE;
        -:  161:
  1478991:  162:  pool->allocated_elements = 0;
        -:  163:  
        -:  164:  /* pick a size for the first block; it increases
        -:  165:   * for each block we need to allocate. This is
        -:  166:   * actually half the initial block size
        -:  167:   * since _dbus_mem_pool_alloc() unconditionally
        -:  168:   * doubles it prior to creating a new block.  */
  1478991:  169:  pool->block_size = pool->element_size * 8;
        -:  170:
  1478991:  171:  _dbus_assert ((pool->block_size %
call    0 returned 100%
        -:  172:                 pool->element_size) == 0);
        -:  173:  
  1478991:  174:  return pool;
        -:  175:}
        -:  176:
        -:  177:/**
        -:  178: * Frees a memory pool (and all elements allocated from it).
        -:  179: *
        -:  180: * @param pool the memory pool.
        -:  181: */
        -:  182:void
        -:  183:_dbus_mem_pool_free (DBusMemPool *pool)
function _dbus_mem_pool_free called 1477223 returned 100% blocks executed 100%
  1477223:  184:{
        -:  185:  DBusMemBlock *block;
        -:  186:
  1477223:  187:  block = pool->blocks;
  4418181:  188:  while (block != NULL)
branch  0 taken 50%
branch  1 taken 50% (fallthrough)
        -:  189:    {
  1463735:  190:      DBusMemBlock *next = block->next;
        -:  191:
  1463735:  192:      dbus_free (block);
call    0 returned 100%
        -:  193:
  1463735:  194:      block = next;
        -:  195:    }
        -:  196:
  1477223:  197:  dbus_free (pool);
call    0 returned 100%
  1477223:  198:}
        -:  199:
        -:  200:/**
        -:  201: * Allocates an object from the memory pool.
        -:  202: * The object must be freed with _dbus_mem_pool_dealloc().
        -:  203: *
        -:  204: * @param pool the memory pool
        -:  205: * @returns the allocated object or #NULL if no memory.
        -:  206: */
        -:  207:void*
        -:  208:_dbus_mem_pool_alloc (DBusMemPool *pool)
function _dbus_mem_pool_alloc called 5779275 returned 100% blocks executed 76%
  5779275:  209:{
        -:  210:#ifdef DBUS_BUILD_TESTS
  5779275:  211:  if (_dbus_disable_mem_pools ())
call    0 returned 100%
branch  1 taken 0% (fallthrough)
branch  2 taken 100%
        -:  212:    {
        -:  213:      DBusMemBlock *block;
        -:  214:      int alloc_size;
        -:  215:      
        -:  216:      /* This is obviously really silly, but it's
        -:  217:       * debug-mode-only code that is compiled out
        -:  218:       * when tests are disabled (_dbus_disable_mem_pools()
        -:  219:       * is a constant expression FALSE so this block
        -:  220:       * should vanish)
        -:  221:       */
        -:  222:      
    #####:  223:      alloc_size = sizeof (DBusMemBlock) - ELEMENT_PADDING +
        -:  224:        pool->element_size;
        -:  225:      
    #####:  226:      if (pool->zero_elements)
branch  0 never executed
branch  1 never executed
    #####:  227:        block = dbus_malloc0 (alloc_size);
call    0 never executed
        -:  228:      else
    #####:  229:        block = dbus_malloc (alloc_size);
call    0 never executed
        -:  230:
    #####:  231:      if (block != NULL)
branch  0 never executed
branch  1 never executed
        -:  232:        {
    #####:  233:          block->next = pool->blocks;
    #####:  234:          pool->blocks = block;
    #####:  235:          pool->allocated_elements += 1;
        -:  236:
    #####:  237:          return (void*) &block->elements[0];
        -:  238:        }
        -:  239:      else
    #####:  240:        return NULL;
        -:  241:    }
        -:  242:  else
        -:  243:#endif
        -:  244:    {
  5779275:  245:      if (_dbus_decrement_fail_alloc_counter ())
call    0 returned 100%
branch  1 taken 1% (fallthrough)
branch  2 taken 99%
        -:  246:        {
     7225:  247:          _dbus_verbose (" FAILING mempool alloc\n");
call    0 returned 100%
     7225:  248:          return NULL;
        -:  249:        }
  5772050:  250:      else if (pool->free_elements)
branch  0 taken 73% (fallthrough)
branch  1 taken 27%
        -:  251:        {
  4229259:  252:          DBusFreedElement *element = pool->free_elements;
        -:  253:
  4229259:  254:          pool->free_elements = pool->free_elements->next;
        -:  255:
  4229259:  256:          if (pool->zero_elements)
branch  0 taken 69% (fallthrough)
branch  1 taken 31%
  2921099:  257:            memset (element, '\0', pool->element_size);
call    0 returned 100%
        -:  258:
  4229259:  259:          pool->allocated_elements += 1;
        -:  260:          
  4229259:  261:          return element;
        -:  262:        }
        -:  263:      else
        -:  264:        {
        -:  265:          void *element;
        -:  266:      
  1542791:  267:          if (pool->blocks == NULL ||
branch  0 taken 5% (fallthrough)
branch  1 taken 95%
branch  2 taken 1% (fallthrough)
branch  3 taken 99%
        -:  268:              pool->blocks->used_so_far == pool->block_size)
        -:  269:            {
        -:  270:              /* Need a new block */
        -:  271:              DBusMemBlock *block;
        -:  272:              int alloc_size;
        -:  273:#ifdef DBUS_BUILD_TESTS
        -:  274:              int saved_counter;
        -:  275:#endif
        -:  276:          
  1465502:  277:              if (pool->block_size <= _DBUS_INT_MAX / 4) /* avoid overflow */
branch  0 taken 100% (fallthrough)
branch  1 taken 0%
        -:  278:                {
        -:  279:                  /* use a larger block size for our next block */
  1465502:  280:                  pool->block_size *= 2;
  1465502:  281:                  _dbus_assert ((pool->block_size %
call    0 returned 100%
        -:  282:                                 pool->element_size) == 0);
        -:  283:                }
        -:  284:
  1465502:  285:              alloc_size = sizeof (DBusMemBlock) - ELEMENT_PADDING + pool->block_size;
        -:  286:
        -:  287:#ifdef DBUS_BUILD_TESTS
        -:  288:              /* We save/restore the counter, so that memory pools won't
        -:  289:               * cause a given function to have different number of
        -:  290:               * allocations on different invocations. i.e.  when testing
        -:  291:               * we want consistent alloc patterns. So we skip our
        -:  292:               * malloc here for purposes of failed alloc simulation.
        -:  293:               */
  1465502:  294:              saved_counter = _dbus_get_fail_alloc_counter ();
call    0 returned 100%
  1465502:  295:              _dbus_set_fail_alloc_counter (_DBUS_INT_MAX);
call    0 returned 100%
        -:  296:#endif
        -:  297:          
  1465502:  298:              if (pool->zero_elements)
branch  0 taken 99% (fallthrough)
branch  1 taken 1%
  1465472:  299:                block = dbus_malloc0 (alloc_size);
call    0 returned 100%
        -:  300:              else
       30:  301:                block = dbus_malloc (alloc_size);
call    0 returned 100%
        -:  302:
        -:  303:#ifdef DBUS_BUILD_TESTS
  1465502:  304:              _dbus_set_fail_alloc_counter (saved_counter);
call    0 returned 100%
  1465502:  305:              _dbus_assert (saved_counter == _dbus_get_fail_alloc_counter ());
call    0 returned 100%
call    1 returned 100%
        -:  306:#endif
        -:  307:          
  1465502:  308:              if (block == NULL)
branch  0 taken 0% (fallthrough)
branch  1 taken 100%
    #####:  309:                return NULL;
        -:  310:
  1465502:  311:              block->used_so_far = 0;
  1465502:  312:              block->next = pool->blocks;
  1465502:  313:              pool->blocks = block;          
        -:  314:            }
        -:  315:      
  1542791:  316:          element = &pool->blocks->elements[pool->blocks->used_so_far];
        -:  317:          
  1542791:  318:          pool->blocks->used_so_far += pool->element_size;
        -:  319:
  1542791:  320:          pool->allocated_elements += 1;
        -:  321:          
  1542791:  322:          return element;
        -:  323:        }
        -:  324:    }
        -:  325:}
        -:  326:
        -:  327:/**
        -:  328: * Deallocates an object previously created with
        -:  329: * _dbus_mem_pool_alloc(). The previous object
        -:  330: * must have come from this same pool.
        -:  331: * @param pool the memory pool
        -:  332: * @param element the element earlier allocated.
        -:  333: * @returns #TRUE if there are no remaining allocated elements
        -:  334: */
        -:  335:dbus_bool_t
        -:  336:_dbus_mem_pool_dealloc (DBusMemPool *pool,
        -:  337:                        void        *element)
function _dbus_mem_pool_dealloc called 5766974 returned 100% blocks executed 28%
  5766974:  338:{
        -:  339:#ifdef DBUS_BUILD_TESTS
  5766974:  340:  if (_dbus_disable_mem_pools ())
call    0 returned 100%
branch  1 taken 0% (fallthrough)
branch  2 taken 100%
        -:  341:    {
        -:  342:      DBusMemBlock *block;
        -:  343:      DBusMemBlock *prev;
        -:  344:
        -:  345:      /* mmm, fast. ;-) debug-only code, so doesn't matter. */
        -:  346:      
    #####:  347:      prev = NULL;
    #####:  348:      block = pool->blocks;
        -:  349:
    #####:  350:      while (block != NULL)
branch  0 never executed
branch  1 never executed
        -:  351:        {
    #####:  352:          if (block->elements == (unsigned char*) element)
branch  0 never executed
branch  1 never executed
        -:  353:            {
    #####:  354:              if (prev)
branch  0 never executed
branch  1 never executed
    #####:  355:                prev->next = block->next;
        -:  356:              else
    #####:  357:                pool->blocks = block->next;
        -:  358:              
    #####:  359:              dbus_free (block);
call    0 never executed
        -:  360:
    #####:  361:              _dbus_assert (pool->allocated_elements > 0);
call    0 never executed
    #####:  362:              pool->allocated_elements -= 1;
        -:  363:              
    #####:  364:              if (pool->allocated_elements == 0)
branch  0 never executed
branch  1 never executed
    #####:  365:                _dbus_assert (pool->blocks == NULL);
call    0 never executed
        -:  366:              
    #####:  367:              return pool->blocks == NULL;
        -:  368:            }
    #####:  369:          prev = block;
    #####:  370:          block = block->next;
        -:  371:        }
        -:  372:      
    #####:  373:      _dbus_assert_not_reached ("freed nonexistent block");
call    0 never executed
        -:  374:      return FALSE;
        -:  375:    }
        -:  376:  else
        -:  377:#endif
        -:  378:    {
        -:  379:      DBusFreedElement *freed;
        -:  380:      
  5766974:  381:      freed = element;
  5766974:  382:      freed->next = pool->free_elements;
  5766974:  383:      pool->free_elements = freed;
        -:  384:      
  5766974:  385:      _dbus_assert (pool->allocated_elements > 0);
call    0 returned 100%
  5766974:  386:      pool->allocated_elements -= 1;
        -:  387:      
  5766974:  388:      return pool->allocated_elements == 0;
        -:  389:    }
        -:  390:}
        -:  391:
        -:  392:/** @} */
        -:  393:
        -:  394:#ifdef DBUS_BUILD_TESTS
        -:  395:#include "dbus-test.h"
        -:  396:#include <stdio.h>
        -:  397:#include <time.h>
        -:  398:
        -:  399:static void
        -:  400:time_for_size (int size)
function time_for_size called 5 returned 100% blocks executed 100%
        5:  401:{
        -:  402:  int i;
        -:  403:  int j;
        -:  404:  clock_t start;
        -:  405:  clock_t end;
        -:  406:#define FREE_ARRAY_SIZE 512
        -:  407:#define N_ITERATIONS FREE_ARRAY_SIZE * 512
        -:  408:  void *to_free[FREE_ARRAY_SIZE];
        -:  409:  DBusMemPool *pool;
        -:  410:
        5:  411:  _dbus_verbose ("Timings for size %d\n", size);
call    0 returned 100%
        -:  412:  
        5:  413:  _dbus_verbose (" malloc\n");
call    0 returned 100%
        -:  414:  
        5:  415:  start = clock ();
call    0 returned 100%
        -:  416:  
        5:  417:  i = 0;
        5:  418:  j = 0;
  1310730:  419:  while (i < N_ITERATIONS)
branch  0 taken 99%
branch  1 taken 1% (fallthrough)
        -:  420:    {
  1310720:  421:      to_free[j] = dbus_malloc (size);
call    0 returned 100%
  1310720:  422:      _dbus_assert (to_free[j] != NULL); /* in a real app of course this is wrong */
call    0 returned 100%
        -:  423:
  1310720:  424:      ++j;
        -:  425:
  1310720:  426:      if (j == FREE_ARRAY_SIZE)
branch  0 taken 1% (fallthrough)
branch  1 taken 99%
        -:  427:        {
     2560:  428:          j = 0;
  1315840:  429:          while (j < FREE_ARRAY_SIZE)
branch  0 taken 99%
branch  1 taken 1% (fallthrough)
        -:  430:            {
  1310720:  431:              dbus_free (to_free[j]);
call    0 returned 100%
  1310720:  432:              ++j;
        -:  433:            }
        -:  434:
     2560:  435:          j = 0;
        -:  436:        }
        -:  437:      
  1310720:  438:      ++i;
        -:  439:    }
        -:  440:
        5:  441:  end = clock ();
call    0 returned 100%
        -:  442:
        5:  443:  _dbus_verbose ("  created/destroyed %d elements in %g seconds\n",
call    0 returned 100%
        -:  444:                 N_ITERATIONS, (end - start) / (double) CLOCKS_PER_SEC);
        -:  445:
        -:  446:
        -:  447:
        5:  448:  _dbus_verbose (" mempools\n");
call    0 returned 100%
        -:  449:  
        5:  450:  start = clock ();
call    0 returned 100%
        -:  451:
        5:  452:  pool = _dbus_mem_pool_new (size, FALSE);
call    0 returned 100%
        -:  453:  
        5:  454:  i = 0;
        5:  455:  j = 0;
  1310730:  456:  while (i < N_ITERATIONS)
branch  0 taken 99%
branch  1 taken 1% (fallthrough)
        -:  457:    {
  1310720:  458:      to_free[j] = _dbus_mem_pool_alloc (pool); 
call    0 returned 100%
  1310720:  459:      _dbus_assert (to_free[j] != NULL);  /* in a real app of course this is wrong */
call    0 returned 100%
        -:  460:
  1310720:  461:      ++j;
        -:  462:
  1310720:  463:      if (j == FREE_ARRAY_SIZE)
branch  0 taken 1% (fallthrough)
branch  1 taken 99%
        -:  464:        {
     2560:  465:          j = 0;
  1315840:  466:          while (j < FREE_ARRAY_SIZE)
branch  0 taken 99%
branch  1 taken 1% (fallthrough)
        -:  467:            {
  1310720:  468:              _dbus_mem_pool_dealloc (pool, to_free[j]);
call    0 returned 100%
  1310720:  469:              ++j;
        -:  470:            }
        -:  471:
     2560:  472:          j = 0;
        -:  473:        }
        -:  474:      
  1310720:  475:      ++i;
        -:  476:    }
        -:  477:
        5:  478:  _dbus_mem_pool_free (pool);
call    0 returned 100%
        -:  479:  
        5:  480:  end = clock ();
call    0 returned 100%
        -:  481:
        5:  482:  _dbus_verbose ("  created/destroyed %d elements in %g seconds\n",
call    0 returned 100%
        -:  483:                 N_ITERATIONS, (end - start) / (double) CLOCKS_PER_SEC);
        -:  484:
        5:  485:  _dbus_verbose (" zeroed malloc\n");
call    0 returned 100%
        -:  486:    
        5:  487:  start = clock ();
call    0 returned 100%
        -:  488:  
        5:  489:  i = 0;
        5:  490:  j = 0;
  1310730:  491:  while (i < N_ITERATIONS)
branch  0 taken 99%
branch  1 taken 1% (fallthrough)
        -:  492:    {
  1310720:  493:      to_free[j] = dbus_malloc0 (size);
call    0 returned 100%
  1310720:  494:      _dbus_assert (to_free[j] != NULL); /* in a real app of course this is wrong */
call    0 returned 100%
        -:  495:
  1310720:  496:      ++j;
        -:  497:
  1310720:  498:      if (j == FREE_ARRAY_SIZE)
branch  0 taken 1% (fallthrough)
branch  1 taken 99%
        -:  499:        {
     2560:  500:          j = 0;
  1315840:  501:          while (j < FREE_ARRAY_SIZE)
branch  0 taken 99%
branch  1 taken 1% (fallthrough)
        -:  502:            {
  1310720:  503:              dbus_free (to_free[j]);
call    0 returned 100%
  1310720:  504:              ++j;
        -:  505:            }
        -:  506:
     2560:  507:          j = 0;
        -:  508:        }
        -:  509:      
  1310720:  510:      ++i;
        -:  511:    }
        -:  512:
        5:  513:  end = clock ();
call    0 returned 100%
        -:  514:
        5:  515:  _dbus_verbose ("  created/destroyed %d elements in %g seconds\n",
call    0 returned 100%
        -:  516:                 N_ITERATIONS, (end - start) / (double) CLOCKS_PER_SEC);
        -:  517:  
        5:  518:  _dbus_verbose (" zeroed mempools\n");
call    0 returned 100%
        -:  519:  
        5:  520:  start = clock ();
call    0 returned 100%
        -:  521:
        5:  522:  pool = _dbus_mem_pool_new (size, TRUE);
call    0 returned 100%
        -:  523:  
        5:  524:  i = 0;
        5:  525:  j = 0;
  1310730:  526:  while (i < N_ITERATIONS)
branch  0 taken 99%
branch  1 taken 1% (fallthrough)
        -:  527:    {
  1310720:  528:      to_free[j] = _dbus_mem_pool_alloc (pool); 
call    0 returned 100%
  1310720:  529:      _dbus_assert (to_free[j] != NULL);  /* in a real app of course this is wrong */
call    0 returned 100%
        -:  530:
  1310720:  531:      ++j;
        -:  532:
  1310720:  533:      if (j == FREE_ARRAY_SIZE)
branch  0 taken 1% (fallthrough)
branch  1 taken 99%
        -:  534:        {
     2560:  535:          j = 0;
  1315840:  536:          while (j < FREE_ARRAY_SIZE)
branch  0 taken 99%
branch  1 taken 1% (fallthrough)
        -:  537:            {
  1310720:  538:              _dbus_mem_pool_dealloc (pool, to_free[j]);
call    0 returned 100%
  1310720:  539:              ++j;
        -:  540:            }
        -:  541:
     2560:  542:          j = 0;
        -:  543:        }
        -:  544:      
  1310720:  545:      ++i;
        -:  546:    }
        -:  547:
        5:  548:  _dbus_mem_pool_free (pool);
call    0 returned 100%
        -:  549:  
        5:  550:  end = clock ();
call    0 returned 100%
        -:  551:
        5:  552:  _dbus_verbose ("  created/destroyed %d elements in %g seconds\n",
call    0 returned 100%
        -:  553:                 N_ITERATIONS, (end - start) / (double) CLOCKS_PER_SEC);
        5:  554:}
        -:  555:
        -:  556:/**
        -:  557: * @ingroup DBusMemPoolInternals
        -:  558: * Unit test for DBusMemPool
        -:  559: * @returns #TRUE on success.
        -:  560: */
        -:  561:dbus_bool_t
        -:  562:_dbus_mem_pool_test (void)
function _dbus_mem_pool_test called 1 returned 100% blocks executed 100%
        1:  563:{
        -:  564:  int i;
        1:  565:  int element_sizes[] = { 4, 8, 16, 50, 124 };
        -:  566:  
        1:  567:  i = 0;
        7:  568:  while (i < _DBUS_N_ELEMENTS (element_sizes))
branch  0 taken 83%
branch  1 taken 17% (fallthrough)
        -:  569:    {
        5:  570:      time_for_size (element_sizes[i]);
call    0 returned 100%
        5:  571:      ++i;
        -:  572:    }
        -:  573:  
        1:  574:  return TRUE;
        -:  575:}
        -:  576:
        -:  577:#endif /* DBUS_BUILD_TESTS */