Lines Matching refs:block

381 static size_t block_size(const block_header_t * block)  in block_size()  argument
383 return block->size & ~(block_header_free_bit | block_header_prev_free_bit); in block_size()
386 static void block_set_size(block_header_t * block, size_t size) in block_set_size() argument
388 const size_t oldsize = block->size; in block_set_size()
389 block->size = size | (oldsize & (block_header_free_bit | block_header_prev_free_bit)); in block_set_size()
392 static int block_is_last(const block_header_t * block) in block_is_last() argument
394 return block_size(block) == 0; in block_is_last()
397 static int block_is_free(const block_header_t * block) in block_is_free() argument
399 return tlsf_cast(int, block->size & block_header_free_bit); in block_is_free()
402 static void block_set_free(block_header_t * block) in block_set_free() argument
404 block->size |= block_header_free_bit; in block_set_free()
407 static void block_set_used(block_header_t * block) in block_set_used() argument
409 block->size &= ~block_header_free_bit; in block_set_used()
412 static int block_is_prev_free(const block_header_t * block) in block_is_prev_free() argument
414 return tlsf_cast(int, block->size & block_header_prev_free_bit); in block_is_prev_free()
417 static void block_set_prev_free(block_header_t * block) in block_set_prev_free() argument
419 block->size |= block_header_prev_free_bit; in block_set_prev_free()
422 static void block_set_prev_used(block_header_t * block) in block_set_prev_used() argument
424 block->size &= ~block_header_prev_free_bit; in block_set_prev_used()
433 static void * block_to_ptr(const block_header_t * block) in block_to_ptr() argument
436 tlsf_cast(unsigned char *, block) + block_start_offset); in block_to_ptr()
446 static block_header_t * block_prev(const block_header_t * block) in block_prev() argument
448 tlsf_assert(block_is_prev_free(block) && "previous block must be free"); in block_prev()
449 return block->prev_phys_block; in block_prev()
453 static block_header_t * block_next(const block_header_t * block) in block_next() argument
455 block_header_t * next = offset_to_block(block_to_ptr(block), in block_next()
456 block_size(block) - block_header_overhead); in block_next()
457 tlsf_assert(!block_is_last(block)); in block_next()
462 static block_header_t * block_link_next(block_header_t * block) in block_link_next() argument
464 block_header_t * next = block_next(block); in block_link_next()
465 next->prev_phys_block = block; in block_link_next()
469 static void block_mark_as_free(block_header_t * block) in block_mark_as_free() argument
472 block_header_t * next = block_link_next(block); in block_mark_as_free()
474 block_set_free(block); in block_mark_as_free()
477 static void block_mark_as_used(block_header_t * block) in block_mark_as_used() argument
479 block_header_t * next = block_next(block); in block_mark_as_used()
481 block_set_used(block); in block_mark_as_used()
585 static void remove_free_block(control_t * control, block_header_t * block, int fl, int sl) in remove_free_block() argument
587 block_header_t * prev = block->prev_free; in remove_free_block()
588 block_header_t * next = block->next_free; in remove_free_block()
595 if(control->blocks[fl][sl] == block) { in remove_free_block()
611 static void insert_free_block(control_t * control, block_header_t * block, int fl, int sl) in insert_free_block() argument
615 tlsf_assert(block && "cannot insert a null entry into the free list"); in insert_free_block()
616 block->next_free = current; in insert_free_block()
617 block->prev_free = &control->block_null; in insert_free_block()
618 current->prev_free = block; in insert_free_block()
620 tlsf_assert(block_to_ptr(block) == align_ptr(block_to_ptr(block), ALIGN_SIZE) in insert_free_block()
626 control->blocks[fl][sl] = block; in insert_free_block()
632 static void block_remove(control_t * control, block_header_t * block) in block_remove() argument
635 mapping_insert(block_size(block), &fl, &sl); in block_remove()
636 remove_free_block(control, block, fl, sl); in block_remove()
640 static void block_insert(control_t * control, block_header_t * block) in block_insert() argument
643 mapping_insert(block_size(block), &fl, &sl); in block_insert()
644 insert_free_block(control, block, fl, sl); in block_insert()
647 static int block_can_split(block_header_t * block, size_t size) in block_can_split() argument
649 return block_size(block) >= sizeof(block_header_t) + size; in block_can_split()
653 static block_header_t * block_split(block_header_t * block, size_t size) in block_split() argument
657 offset_to_block(block_to_ptr(block), size - block_header_overhead); in block_split()
659 const size_t remain_size = block_size(block) - (size + block_header_overhead); in block_split()
664 tlsf_assert(block_size(block) == remain_size + size + block_header_overhead); in block_split()
668 block_set_size(block, size); in block_split()
675 static block_header_t * block_absorb(block_header_t * prev, block_header_t * block) in block_absorb() argument
679 prev->size += block_size(block) + block_header_overhead; in block_absorb()
685 static block_header_t * block_merge_prev(control_t * control, block_header_t * block) in block_merge_prev() argument
687 if(block_is_prev_free(block)) { in block_merge_prev()
688 block_header_t * prev = block_prev(block); in block_merge_prev()
692 block = block_absorb(prev, block); in block_merge_prev()
695 return block; in block_merge_prev()
699 static block_header_t * block_merge_next(control_t * control, block_header_t * block) in block_merge_next() argument
701 block_header_t * next = block_next(block); in block_merge_next()
705 tlsf_assert(!block_is_last(block) && "previous block can't be last"); in block_merge_next()
707 block = block_absorb(block, next); in block_merge_next()
710 return block; in block_merge_next()
714 static void block_trim_free(control_t * control, block_header_t * block, size_t size) in block_trim_free() argument
716 tlsf_assert(block_is_free(block) && "block must be free"); in block_trim_free()
717 if(block_can_split(block, size)) { in block_trim_free()
718 block_header_t * remaining_block = block_split(block, size); in block_trim_free()
719 block_link_next(block); in block_trim_free()
726 static void block_trim_used(control_t * control, block_header_t * block, size_t size) in block_trim_used() argument
728 tlsf_assert(!block_is_free(block) && "block must be used"); in block_trim_used()
729 if(block_can_split(block, size)) { in block_trim_used()
731 block_header_t * remaining_block = block_split(block, size); in block_trim_used()
739 static block_header_t * block_trim_free_leading(control_t * control, block_header_t * block, size_t… in block_trim_free_leading() argument
741 block_header_t * remaining_block = block; in block_trim_free_leading()
742 if(block_can_split(block, size)) { in block_trim_free_leading()
744 remaining_block = block_split(block, size - block_header_overhead); in block_trim_free_leading()
747 block_link_next(block); in block_trim_free_leading()
748 block_insert(control, block); in block_trim_free_leading()
757 block_header_t * block = 0; in block_locate_free() local
769 block = search_suitable_block(control, &fl, &sl); in block_locate_free()
773 if(block) { in block_locate_free()
774 tlsf_assert(block_size(block) >= size); in block_locate_free()
775 remove_free_block(control, block, fl, sl); in block_locate_free()
778 return block; in block_locate_free()
781 static void * block_prepare_used(control_t * control, block_header_t * block, size_t size) in block_prepare_used() argument
784 if(block) { in block_prepare_used()
786 block_trim_free(control, block, size); in block_prepare_used()
787 block_mark_as_used(block); in block_prepare_used()
788 p = block_to_ptr(block); in block_prepare_used()
823 block_header_t * block = block_from_ptr(ptr); in integrity_walker() local
825 const int this_prev_status = block_is_prev_free(block) ? 1 : 0; in integrity_walker()
826 const int this_status = block_is_free(block) ? 1 : 0; in integrity_walker()
827 const size_t this_block_size = block_size(block); in integrity_walker()
851 const block_header_t * block = control->blocks[i][j]; in lv_tlsf_check() local
859 tlsf_insist(block == &control->block_null && "block list must be null"); in lv_tlsf_check()
865 tlsf_insist(block != &control->block_null && "block should not be null"); in lv_tlsf_check()
867 while(block != &control->block_null) { in lv_tlsf_check()
869 tlsf_insist(block_is_free(block) && "block should be free"); in lv_tlsf_check()
870 tlsf_insist(!block_is_prev_free(block) && "blocks should have coalesced"); in lv_tlsf_check()
871 tlsf_insist(!block_is_free(block_next(block)) && "blocks should have coalesced"); in lv_tlsf_check()
872 tlsf_insist(block_is_prev_free(block_next(block)) && "block should be free"); in lv_tlsf_check()
873 tlsf_insist(block_size(block) >= block_size_min && "block not minimum size"); in lv_tlsf_check()
875 mapping_insert(block_size(block), &fli, &sli); in lv_tlsf_check()
877 block = block->next_free; in lv_tlsf_check()
896 block_header_t * block = in lv_tlsf_walk_pool() local
899 while(block && !block_is_last(block)) { in lv_tlsf_walk_pool()
901 block_to_ptr(block), in lv_tlsf_walk_pool()
902 block_size(block), in lv_tlsf_walk_pool()
903 !block_is_free(block), in lv_tlsf_walk_pool()
905 block = block_next(block); in lv_tlsf_walk_pool()
913 const block_header_t * block = block_from_ptr(ptr); in lv_tlsf_block_size() local
914 size = block_size(block); in lv_tlsf_block_size()
969 block_header_t * block; in lv_tlsf_add_pool() local
999 block = offset_to_block(mem, -(tlsfptr_t)block_header_overhead); in lv_tlsf_add_pool()
1000 block_set_size(block, pool_bytes); in lv_tlsf_add_pool()
1001 block_set_free(block); in lv_tlsf_add_pool()
1002 block_set_prev_used(block); in lv_tlsf_add_pool()
1003 block_insert(tlsf_cast(control_t *, tlsf), block); in lv_tlsf_add_pool()
1006 next = block_link_next(block); in lv_tlsf_add_pool()
1017 block_header_t * block = offset_to_block(pool, -(int)block_header_overhead); in lv_tlsf_remove_pool() local
1021 tlsf_assert(block_is_free(block) && "block should be free"); in lv_tlsf_remove_pool()
1022 tlsf_assert(!block_is_free(block_next(block)) && "next block should not be free"); in lv_tlsf_remove_pool()
1023 tlsf_assert(block_size(block_next(block)) == 0 && "next block size should be zero"); in lv_tlsf_remove_pool()
1025 mapping_insert(block_size(block), &fl, &sl); in lv_tlsf_remove_pool()
1026 remove_free_block(control, block, fl, sl); in lv_tlsf_remove_pool()
1101 block_header_t * block = block_locate_free(control, adjust); in lv_tlsf_malloc() local
1102 return block_prepare_used(control, block, adjust); in lv_tlsf_malloc()
1127 block_header_t * block = block_locate_free(control, aligned_size); in lv_tlsf_memalign() local
1132 if(block) { in lv_tlsf_memalign()
1133 void * ptr = block_to_ptr(block); in lv_tlsf_memalign()
1152 block = block_trim_free_leading(control, block, gap); in lv_tlsf_memalign()
1156 return block_prepare_used(control, block, adjust); in lv_tlsf_memalign()
1165 block_header_t * block = block_from_ptr(ptr); in lv_tlsf_free() local
1166 tlsf_assert(!block_is_free(block) && "block already marked as free"); in lv_tlsf_free()
1167 size = block->size; in lv_tlsf_free()
1168 block_mark_as_free(block); in lv_tlsf_free()
1169 block = block_merge_prev(control, block); in lv_tlsf_free()
1170 block = block_merge_next(control, block); in lv_tlsf_free()
1171 block_insert(control, block); in lv_tlsf_free()
1204 block_header_t * block = block_from_ptr(ptr); in lv_tlsf_realloc() local
1205 block_header_t * next = block_next(block); in lv_tlsf_realloc()
1207 const size_t cursize = block_size(block); in lv_tlsf_realloc()
1215 tlsf_assert(!block_is_free(block) && "block already marked as free"); in lv_tlsf_realloc()
1232 block_merge_next(control, block); in lv_tlsf_realloc()
1233 block_mark_as_used(block); in lv_tlsf_realloc()
1237 block_trim_used(control, block, adjust); in lv_tlsf_realloc()