heap_init_free_block.c 1.4 KB

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