heap_init_free_block.c 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. #include "private.h"
  2. /*--------------------------------------------------------- */
  3. void
  4. lub_heap_init_free_block(lub_heap_t * this,
  5. void *start,
  6. size_t size, bool_t seg_start, bool_t seg_end)
  7. {
  8. lub_heap_free_block_t *block = start;
  9. lub_heap_tag_t *tail;
  10. words_t words;
  11. /* initialise the given memory */
  12. lub_heap_taint_memory(start, LUB_HEAP_TAINT_FREE, size);
  13. /* calculate the number of words in this segment */
  14. words = (size >> 2);
  15. /* setup the block */
  16. block->tag.segment = seg_start; /* start of a segment */
  17. block->tag.free = 1;
  18. block->tag.words = words;
  19. /* initialise the tree node */
  20. lub_bintree_node_init(&block->bt_node);
  21. /* now fill out the trailing tag */
  22. tail = lub_heap_block__get_tail((lub_heap_block_t *) block);
  23. tail->segment = seg_end; /* end of a segment */
  24. tail->free = 1;
  25. tail->words = words;
  26. /* now insert this free block into the tree */
  27. lub_bintree_insert(&this->free_tree, block);
  28. ++this->stats.free_blocks;
  29. this->stats.free_bytes += (words << 2);
  30. this->stats.free_bytes -= sizeof(lub_heap_alloc_block_t);
  31. this->stats.free_overhead += sizeof(lub_heap_alloc_block_t);
  32. }
  33. /*--------------------------------------------------------- */