From d36a1487036277e413d0028398071a6cd3ca5cc6 Mon Sep 17 00:00:00 2001 From: hyung-hwan Date: Wed, 4 Nov 2020 06:36:44 +0000 Subject: [PATCH] some code clean and adding one more kill point for halted devices --- mio/lib/mio.c | 22 ++++++++++++++-------- mio/lib/tmr.c | 2 +- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/mio/lib/mio.c b/mio/lib/mio.c index d18c332..e733cc4 100644 --- a/mio/lib/mio.c +++ b/mio/lib/mio.c @@ -733,6 +733,17 @@ static void clear_unneeded_cfmbs (mio_t* mio) } } +static void kill_all_halted_devices (mio_t* mio) +{ + /* kill all halted devices */ + while (!MIO_DEVL_IS_EMPTY(&mio->hltdev)) + { + mio_dev_t* dev = MIO_DEVL_FIRST_DEV(&mio->hltdev); + MIO_DEBUG1 (mio, "MIO - Killing HALTED device %p\n", dev); + mio_dev_kill (dev); + } +} + int mio_exec (mio_t* mio) { int ret = 0; @@ -757,6 +768,8 @@ int mio_exec (mio_t* mio) /* wait on the multiplexer only if there is at least 1 active device */ mio_ntime_t tmout; + kill_all_halted_devices (mio); + if (mio_gettmrtmout(mio, MIO_NULL, &tmout) <= 0) { /* defaults to 0 or 1 second if timeout can't be acquired. @@ -773,14 +786,7 @@ int mio_exec (mio_t* mio) } } - /* kill all halted devices */ - while (!MIO_DEVL_IS_EMPTY(&mio->hltdev)) - { - mio_dev_t* dev = MIO_DEVL_FIRST_DEV(&mio->hltdev); - MIO_DEBUG1 (mio, "MIO - Killing HALTED device %p\n", dev); - mio_dev_kill (dev); - } - + kill_all_halted_devices (mio); return ret; } diff --git a/mio/lib/tmr.c b/mio/lib/tmr.c index 80a41d1..bb2bc40 100644 --- a/mio/lib/tmr.c +++ b/mio/lib/tmr.c @@ -158,7 +158,7 @@ mio_tmridx_t mio_updtmrjob (mio_t* mio, mio_tmridx_t index, const mio_tmrjob_t* item = mio->tmr.jobs[index]; mio->tmr.jobs[index] = *job; if (mio->tmr.jobs[index].idxptr) *mio->tmr.jobs[index].idxptr = index; - return YOUNGER_THAN(job, &item)? sift_up (mio, index): sift_down (mio, index); + return YOUNGER_THAN(job, &item)? sift_up(mio, index): sift_down(mio, index); } void mio_firetmrjobs (mio_t* mio, const mio_ntime_t* tm, mio_oow_t* firecnt)