enhanced to reuse some cwq objects once allocated with dstaddr of size 0

This commit is contained in:
hyung-hwan 2019-01-14 09:23:16 +00:00
parent ec28cccdd3
commit d0583e95c8
2 changed files with 33 additions and 5 deletions

View File

@ -79,6 +79,7 @@ struct mio_t
} tmr; } tmr;
mio_cwq_t cwq; mio_cwq_t cwq;
mio_cwq_t* cwq_zdf; /* list of free cwq objects with 0-sized dstaddr */
/* platform specific fields below */ /* platform specific fields below */
#if defined(_WIN32) #if defined(_WIN32)

View File

@ -395,6 +395,13 @@ void mio_fini (mio_t* mio)
mio_dev_t* tail; mio_dev_t* tail;
} diehard; } diehard;
while (mio->cwq_zdf)
{
mio_cwq_t* cwq = mio->cwq_zdf;
mio->cwq_zdf = cwq->next;
MIO_MMGR_FREE (mio->mmgr, cwq);
}
/* kill all registered devices */ /* kill all registered devices */
while (mio->actdev.head) while (mio->actdev.head)
{ {
@ -732,8 +739,19 @@ static MIO_INLINE int __exec (mio_t* mio)
if (cwq->dev->dev_evcb->on_write(cwq->dev, cwq->olen, cwq->ctx, &cwq->dstaddr) <= -1) return -1; if (cwq->dev->dev_evcb->on_write(cwq->dev, cwq->olen, cwq->ctx, &cwq->dstaddr) <= -1) return -1;
cwq->dev->cw_count--; cwq->dev->cw_count--;
MIO_CWQ_UNLINK (cwq); MIO_CWQ_UNLINK (cwq);
if (cwq->dstaddr.len == 0)
{
/* reuse the cwq object if dstaddr is 0 in size. chain it to the free list */
cwq->next = mio->cwq_zdf;
mio->cwq_zdf = cwq;
}
else
{
/* TODO: more reuse of objects of different size? */
MIO_MMGR_FREE (mio->mmgr, cwq); MIO_MMGR_FREE (mio->mmgr, cwq);
} }
}
/* execute the scheduled jobs before checking devices with the /* execute the scheduled jobs before checking devices with the
* multiplexer. the scheduled jobs can safely destroy the devices */ * multiplexer. the scheduled jobs can safely destroy the devices */
@ -1416,13 +1434,22 @@ enqueue_data:
enqueue_completed_write: enqueue_completed_write:
/* queue the remaining data*/ /* queue the remaining data*/
if (!dstaddr && dev->mio->cwq_zdf)
{
cwq = dev->mio->cwq_zdf;
dev->mio->cwq_zdf = cwq->next;
}
else
{
cwq = (mio_cwq_t*)MIO_MMGR_ALLOC(dev->mio->mmgr, MIO_SIZEOF(*cwq) + (dstaddr? dstaddr->len: 0)); cwq = (mio_cwq_t*)MIO_MMGR_ALLOC(dev->mio->mmgr, MIO_SIZEOF(*cwq) + (dstaddr? dstaddr->len: 0));
if (!cwq) if (!cwq)
{ {
dev->mio->errnum = MIO_ENOMEM; dev->mio->errnum = MIO_ENOMEM;
return -1; return -1;
} }
}
MIO_MEMSET (cwq, 0, MIO_SIZEOF(*cwq));
cwq->dev = dev; cwq->dev = dev;
cwq->ctx = wrctx; cwq->ctx = wrctx;
if (dstaddr) if (dstaddr)