static tb_void_t tb_fixed_pool_slot_exit(tb_fixed_pool_t* pool, tb_fixed_pool_slot_t* slot) { // check tb_assert_and_check_return(pool && pool->large_allocator && slot); tb_assert_and_check_return(pool->slot_list && pool->slot_count); // trace tb_trace_d("slot[%lu]: exit: size: %lu", pool->item_size, slot->size); // make the iterator tb_array_iterator_t array_iterator; tb_iterator_ref_t iterator = tb_iterator_make_for_ptr(&array_iterator, (tb_pointer_t*)pool->slot_list, pool->slot_count); tb_assert(iterator); // find the slot from the slot list tb_size_t itor = tb_binary_find_all(iterator, (tb_cpointer_t)slot); tb_assert(itor != tb_iterator_tail(iterator) && itor < pool->slot_count && pool->slot_list[itor]); tb_check_return(itor != tb_iterator_tail(iterator) && itor < pool->slot_count && pool->slot_list[itor]); // remove the slot if (itor + 1 < pool->slot_count) tb_memmov_(pool->slot_list + itor, pool->slot_list + itor + 1, (pool->slot_count - itor - 1) * sizeof(tb_fixed_pool_slot_t*)); // update the slot count pool->slot_count--; // exit slot tb_allocator_large_free(pool->large_allocator, slot); }
/* ////////////////////////////////////////////////////////////////////////////////////// * implementation */ tb_iterator_ref_t tb_iterator_make_for_long(tb_array_iterator_ref_t iterator, tb_long_t* items, tb_size_t count) { // make iterator for the pointer array if (!tb_iterator_make_for_ptr(iterator, (tb_pointer_t*)items, count)) return tb_null; // init iterator->base.comp = tb_iterator_long_comp; // ok return (tb_iterator_ref_t)iterator; }
/* ////////////////////////////////////////////////////////////////////////////////////// * implementation */ tb_iterator_ref_t tb_iterator_make_for_mem(tb_array_iterator_ref_t iterator, tb_pointer_t items, tb_size_t count, tb_size_t size) { // check tb_assert_and_check_return_val(size, tb_null); // make iterator for the pointer array if (!tb_iterator_make_for_ptr(iterator, (tb_pointer_t*)items, count)) return tb_null; // init iterator->base.step = size; iterator->base.item = tb_iterator_mem_item; iterator->base.copy = tb_iterator_mem_copy; iterator->base.comp = tb_iterator_mem_comp; // ok return (tb_iterator_ref_t)iterator; }
static tb_fixed_pool_slot_t* tb_fixed_pool_slot_find(tb_fixed_pool_t* pool, tb_pointer_t data) { // check tb_assert_and_check_return_val(pool && data, tb_null); // make the iterator tb_array_iterator_t array_iterator; tb_iterator_ref_t iterator = tb_iterator_make_for_ptr(&array_iterator, (tb_pointer_t*)pool->slot_list, pool->slot_count); tb_assert(iterator); // find it tb_size_t itor = tb_binary_find_all_if(iterator, tb_fixed_pool_slot_comp, data); tb_check_return_val(itor != tb_iterator_tail(iterator), tb_null); // the slot tb_fixed_pool_slot_t* slot = pool->slot_list[itor]; tb_assert_and_check_return_val(slot, tb_null); // check tb_assert(tb_fixed_pool_slot_exists(slot, data)); // ok? return slot; }
/* ////////////////////////////////////////////////////////////////////////////////////// * implementation */ tb_iterator_ref_t tb_iterator_make_for_size(tb_array_iterator_ref_t iterator, tb_size_t* items, tb_size_t count) { // make iterator for the pointer array return tb_iterator_make_for_ptr(iterator, (tb_pointer_t*)items, count); }