changed hawk_xma_free() a bit
This commit is contained in:
parent
4323b0b7ce
commit
105bbf5429
@ -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 */
|
/* shrink the size of the 'cand' block */
|
||||||
cand->size = size;
|
cand->size = size;
|
||||||
|
|
||||||
/* let 'tmp' point to the remaining part */
|
/* let 'y' point to the remaining part */
|
||||||
y = next_mblk(cand); /* get the next adjacent block */
|
y = next_mblk(cand);
|
||||||
|
|
||||||
/* initialize some fields */
|
/* initialize some fields */
|
||||||
y->free = 1;
|
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* blk = (hawk_xma_mblk_t*)USR_TO_SYS(b);
|
||||||
hawk_xma_mblk_t* x, * y;
|
hawk_xma_mblk_t* x, * y;
|
||||||
|
hawk_oow_t org_blk_size;
|
||||||
|
|
||||||
DBG_VERIFY (xma, "free start");
|
DBG_VERIFY (xma, "free start");
|
||||||
|
|
||||||
|
org_blk_size = blk->size;
|
||||||
|
|
||||||
#if defined(HAWK_XMA_ENABLE_STAT)
|
#if defined(HAWK_XMA_ENABLE_STAT)
|
||||||
/* update statistical variables */
|
/* update statistical variables */
|
||||||
xma->stat.nused--;
|
xma->stat.nused--;
|
||||||
xma->stat.alloc -= blk->size;
|
xma->stat.alloc -= org_blk_size;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
x = prev_mblk(blk);
|
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_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;
|
hawk_oow_t bs = ns + y->size;
|
||||||
|
|
||||||
detach_from_freelist (xma, (hawk_xma_fblk_t*)x);
|
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);
|
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 y from the free list */
|
||||||
detach_from_freelist (xma, (hawk_xma_fblk_t*)y);
|
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 blk to the free list */
|
||||||
attach_to_freelist (xma, (hawk_xma_fblk_t*)blk);
|
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)
|
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 |
|
* | X | Y |
|
||||||
* +-------------------------+------------+
|
* +-------------------------+------------+
|
||||||
*/
|
*/
|
||||||
#if defined(HAWK_XMA_ENABLE_STAT)
|
|
||||||
xma->stat.avail += MBLKHDRSIZE + blk->size;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
detach_from_freelist (xma, (hawk_xma_fblk_t*)x);
|
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));
|
HAWK_ASSERT (y == next_mblk(x));
|
||||||
if ((hawk_uint8_t*)y < xma->end) y->prev_size = x->size;
|
if ((hawk_uint8_t*)y < xma->end) y->prev_size = x->size;
|
||||||
|
|
||||||
attach_to_freelist (xma, (hawk_xma_fblk_t*)x);
|
attach_to_freelist (xma, (hawk_xma_fblk_t*)x);
|
||||||
|
|
||||||
|
#if defined(HAWK_XMA_ENABLE_STAT)
|
||||||
|
xma->stat.avail += MBLKHDRSIZE + org_blk_size;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
||||||
blk->free = 1;
|
blk->free = 1;
|
||||||
attach_to_freelist (xma, (hawk_xma_fblk_t*)blk);
|
attach_to_freelist (xma, (hawk_xma_fblk_t*)blk);
|
||||||
|
|
||||||
#if defined(HAWK_XMA_ENABLE_STAT)
|
#if defined(HAWK_XMA_ENABLE_STAT)
|
||||||
xma->stat.nfree++;
|
xma->stat.nfree++;
|
||||||
xma->stat.avail += blk->size;
|
xma->stat.avail += org_blk_size;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user