/********************************************************************//** Fills the specified free list. @return TRUE if we were able to insert a block to the free list */ static ibool mem_pool_fill_free_list( /*====================*/ ulint i, /*!< in: free list index */ mem_pool_t* pool) /*!< in: memory pool */ { mem_area_t* area; mem_area_t* area2; ibool ret; ut_ad(mutex_own(&(pool->mutex))); )) { /* We come here when we have run out of space in the memory pool: */ return(FALSE); } /** *pool->free_list[i]找不到内存块的话,尝试从pool->free_list[i+1]中查找 *如果找不到,一直向上查找 * *如果找到了,从list列表中摘除,并插入到向下的数组元素所在列表中 * *例如:要分配100字节内存,通过计算在pool->free_list[7]中查找 2^7=128 而 2^6=64不符合要求 *如果pool->free_list[7]的头结点为空, *那么从pool->free_list[7+1]中查找并赋值为area,如果找到,将area从pool->free_list[8]中的链表中删除 *将此area取类型强制转为byte*,然后取(byte*)area+ut_2_exp(7) 即取出area一半的地址 *再设置size为ut_2_exp(7) *并设置为pool->free_list[7]的头结点 */ area = UT_LIST_GET_FIRST(pool->free_list[i + ]); if (area == NULL) { ]) > ) { ut_print_timestamp(stderr); fprintf(stderr, " InnoDB: Error: mem pool free list %lu" " length is %lu\n" "InnoDB: though the list is empty!\n", (, (ulong) UT_LIST_GET_LEN(pool->free_list[i + ])); } ret = mem_pool_fill_free_list(i + , pool); if (ret == FALSE) { return(FALSE); } area = UT_LIST_GET_FIRST(pool->free_list[i + ]); } ]) == )) { mem_analyze_corruption(area); ut_error; } UT_LIST_REMOVE(free_list, pool->free_list[i + ], area); area2 = (mem_area_t*)(((byte*)area) + ut_2_exp(i)); UNIV_MEM_ALLOC(area2, MEM_AREA_EXTRA_SIZE); mem_area_set_size(area2, ut_2_exp(i)); mem_area_set_free(area2, TRUE); UT_LIST_ADD_FIRST(free_list, pool->free_list[i], area2); mem_area_set_size(area, ut_2_exp(i)); UT_LIST_ADD_FIRST(free_list, pool->free_list[i], area); return(TRUE); }