From 105bbf5429e2ec03dec66f380133b676b8fa3d9c Mon Sep 17 00:00:00 2001 From: hyung-hwan Date: Tue, 3 Nov 2020 12:59:28 +0000 Subject: [PATCH] changed hawk_xma_free() a bit --- hawk/lib/xma.c | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/hawk/lib/xma.c b/hawk/lib/xma.c index e9226490..bbb97d8e 100644 --- a/hawk/lib/xma.c +++ b/hawk/lib/xma.c @@ -349,8 +349,8 @@ static hawk_xma_fblk_t* alloc_from_freelist (hawk_xma_t* xma, hawk_oow_t xfi, ha /* shrink the size of the 'cand' block */ cand->size = size; - /* let 'tmp' point to the remaining part */ - y = next_mblk(cand); /* get the next adjacent block */ + /* let 'y' point to the remaining part */ + y = next_mblk(cand); /* initialize some fields */ y->free = 1; @@ -647,13 +647,16 @@ void hawk_xma_free (hawk_xma_t* xma, void* b) { hawk_xma_mblk_t* blk = (hawk_xma_mblk_t*)USR_TO_SYS(b); hawk_xma_mblk_t* x, * y; + hawk_oow_t org_blk_size; DBG_VERIFY (xma, "free start"); + org_blk_size = blk->size; + #if defined(HAWK_XMA_ENABLE_STAT) /* update statistical variables */ xma->stat.nused--; - xma->stat.alloc -= blk->size; + xma->stat.alloc -= org_blk_size; #endif x = prev_mblk(blk); @@ -678,7 +681,7 @@ void hawk_xma_free (hawk_xma_t* xma, void* b) */ hawk_xma_mblk_t* z = next_mblk(y); - hawk_oow_t ns = MBLKHDRSIZE + blk->size + MBLKHDRSIZE; + hawk_oow_t ns = MBLKHDRSIZE + org_blk_size + MBLKHDRSIZE; hawk_oow_t bs = ns + y->size; detach_from_freelist (xma, (hawk_xma_fblk_t*)x); @@ -720,10 +723,6 @@ void hawk_xma_free (hawk_xma_t* xma, void* b) */ hawk_xma_mblk_t* z = next_mblk(y); -#if defined(HAWK_XMA_ENABLE_STAT) - xma->stat.avail += blk->size + MBLKHDRSIZE; -#endif - /* detach y from the free list */ detach_from_freelist (xma, (hawk_xma_fblk_t*)y); @@ -737,6 +736,10 @@ void hawk_xma_free (hawk_xma_t* xma, void* b) /* attach blk to the free list */ attach_to_freelist (xma, (hawk_xma_fblk_t*)blk); + +#if defined(HAWK_XMA_ENABLE_STAT) + xma->stat.avail += org_blk_size + MBLKHDRSIZE; +#endif } else if ((hawk_uint8_t*)x >= xma->start && x->free) { @@ -754,28 +757,27 @@ void hawk_xma_free (hawk_xma_t* xma, void* b) * | X | Y | * +-------------------------+------------+ */ -#if defined(HAWK_XMA_ENABLE_STAT) - xma->stat.avail += MBLKHDRSIZE + blk->size; -#endif - detach_from_freelist (xma, (hawk_xma_fblk_t*)x); - x->size += MBLKHDRSIZE + blk->size; + x->size += MBLKHDRSIZE + org_blk_size; HAWK_ASSERT (y == next_mblk(x)); if ((hawk_uint8_t*)y < xma->end) y->prev_size = x->size; attach_to_freelist (xma, (hawk_xma_fblk_t*)x); + +#if defined(HAWK_XMA_ENABLE_STAT) + xma->stat.avail += MBLKHDRSIZE + org_blk_size; +#endif } else { - blk->free = 1; attach_to_freelist (xma, (hawk_xma_fblk_t*)blk); #if defined(HAWK_XMA_ENABLE_STAT) xma->stat.nfree++; - xma->stat.avail += blk->size; + xma->stat.avail += org_blk_size; #endif }