heap_merge_with_next.c 917 B

12345678910111213141516171819202122232425262728293031323334353637
  1. #include <assert.h>
  2. #include "private.h"
  3. /*--------------------------------------------------------- */
  4. lub_heap_status_t
  5. lub_heap_merge_with_next(lub_heap_t * this, lub_heap_block_t * block)
  6. {
  7. lub_heap_status_t result = LUB_HEAP_FAILED;
  8. lub_heap_block_t *next_block;
  9. assert(0 == block->alloc.tag.free);
  10. do {
  11. /* see whether there is a free block just after us */
  12. next_block = lub_heap_block_getnext(block);
  13. if ((NULL != next_block)
  14. && (1 == next_block->free.tag.free)) {
  15. if (BOOL_FALSE == lub_heap_block_check(next_block)) {
  16. result = LUB_HEAP_CORRUPTED;
  17. break;
  18. }
  19. lub_heap_graft_to_bottom(this,
  20. next_block,
  21. block,
  22. block->alloc.tag.words,
  23. block->alloc.tag.segment,
  24. block->free.tag.
  25. free ? BOOL_TRUE : BOOL_FALSE);
  26. result = LUB_HEAP_OK;
  27. }
  28. } while (0);
  29. return result;
  30. }
  31. /*--------------------------------------------------------- */