From 54747b0d7c04aad808923ba617e9060bbdbeb51a Mon Sep 17 00:00:00 2001 From: "hyunghwan.chung" Date: Sun, 18 Feb 2018 15:55:07 +0000 Subject: [PATCH] changed io semaphore signaling code to signal an output semaphore to be triggered upon HANGUP or ERROR if no input semaphore is attached on the IO handle watched --- moo/lib/exec.c | 25 +++++++++++++++++-------- moo/lib/main.c | 4 ++-- 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/moo/lib/exec.c b/moo/lib/exec.c index 4e654b6..77c5859 100644 --- a/moo/lib/exec.c +++ b/moo/lib/exec.c @@ -164,7 +164,8 @@ static MOO_INLINE void vm_cleanup (moo_t* moo) if ((sem_io_index = moo->sem_io_map[i]) >= 0) { MOO_ASSERT (moo, sem_io_index < moo->sem_io_tuple_count); - MOO_ASSERT (moo, moo->sem_io_tuple[sem_io_index].sem[MOO_SEMAPHORE_IO_TYPE_INPUT] || moo->sem_io_tuple[sem_io_index].sem[MOO_SEMAPHORE_IO_TYPE_OUTPUT]); + MOO_ASSERT (moo, moo->sem_io_tuple[sem_io_index].sem[MOO_SEMAPHORE_IO_TYPE_INPUT] || + moo->sem_io_tuple[sem_io_index].sem[MOO_SEMAPHORE_IO_TYPE_OUTPUT]); if (moo->sem_io_tuple[sem_io_index].sem[MOO_SEMAPHORE_IO_TYPE_INPUT]) { @@ -1370,21 +1371,29 @@ static void signal_io_semaphore (moo_t* moo, moo_ooi_t io_handle, moo_ooi_t mask { if (io_handle >= 0 && io_handle < moo->sem_io_map_capa && moo->sem_io_map[io_handle] >= 0) { - moo_oop_semaphore_t sem; + moo_oop_semaphore_t insem, outsem; moo_ooi_t sem_io_index; sem_io_index = moo->sem_io_map[io_handle]; - sem = moo->sem_io_tuple[sem_io_index].sem[MOO_SEMAPHORE_IO_TYPE_OUTPUT]; - if (sem && (mask & MOO_SEMAPHORE_IO_MASK_OUTPUT)) + insem = moo->sem_io_tuple[sem_io_index].sem[MOO_SEMAPHORE_IO_TYPE_OUTPUT]; + outsem = moo->sem_io_tuple[sem_io_index].sem[MOO_SEMAPHORE_IO_TYPE_INPUT]; + + if (insem) { - _signal_io_semaphore (moo, sem); + if ((mask & MOO_SEMAPHORE_IO_MASK_OUTPUT) || + (!outsem && (mask & (MOO_SEMAPHORE_IO_MASK_HANGUP | MOO_SEMAPHORE_IO_MASK_ERROR)))) + { + _signal_io_semaphore (moo, insem); + } } - sem = moo->sem_io_tuple[sem_io_index].sem[MOO_SEMAPHORE_IO_TYPE_INPUT]; - if (sem && (mask & (MOO_SEMAPHORE_IO_MASK_INPUT | MOO_SEMAPHORE_IO_MASK_HANGUP | MOO_SEMAPHORE_IO_MASK_ERROR))) + if (outsem) { - _signal_io_semaphore (moo, sem); + if (mask & (MOO_SEMAPHORE_IO_MASK_INPUT | MOO_SEMAPHORE_IO_MASK_HANGUP | MOO_SEMAPHORE_IO_MASK_ERROR)) + { + _signal_io_semaphore (moo, outsem); + } } } else diff --git a/moo/lib/main.c b/moo/lib/main.c index 8853964..9d5d7e0 100644 --- a/moo/lib/main.c +++ b/moo/lib/main.c @@ -1487,7 +1487,7 @@ static void* iothr_main (void* arg) memcpy (xtn->ev.buf, xtn->ev.reg.ptr, xtn->ev.reg.len * MOO_SIZEOF(*xtn->ev.buf)); nfds = xtn->ev.reg.len; MUTEX_UNLOCK (&xtn->ev.reg.pmtx); - n = poll (xtn->ev.buf, nfds, 10000); + n = poll(xtn->ev.buf, nfds, 10000); if (n > 0) { /* compact the return buffer as poll() doesn't */ @@ -1727,7 +1727,7 @@ static void vm_muxwait (moo_t* moo, const moo_ntime_t* dur, moo_vmprim_muxwait_c n = epoll_wait (xtn->ep, xtn->ev.buf, MOO_COUNTOF(xtn->ev.buf), tmout); #elif defined(USE_POLL) memcpy (xtn->ev.buf, xtn->ev.reg.ptr, xtn->ev.reg.len * MOO_SIZEOF(*xtn->ev.buf)); - n = poll (xtn->ev.buf, xtn->ev.reg.len, tmout); + n = poll(xtn->ev.buf, xtn->ev.reg.len, tmout); if (n > 0) { /* compact the return buffer as poll() doesn't */