diff --git a/moo/kernel/Process.moo b/moo/kernel/Process.moo index b9dc5c9..a8d33f0 100644 --- a/moo/kernel/Process.moo +++ b/moo/kernel/Process.moo @@ -129,64 +129,6 @@ TODO: how to prohibit wait and signal??? ^block ensure: [ self signal ] } } - - -(* - xxx := Semaphore new. - xxx on: #signal do: [ ]. - - - ========= CASE 1 ==================== - sg := SemaphoreGroup with (xxx, yyy, zzz). - System signal: xxx onInput: aaa. - System signal: yyy onInput: bbb. - System signal: zzz onOutput: ccc. - - while (true) - { - sem := sg wait. - if (sem == xxx) - { - - } - elsif (sem == yyy) - { - } - elsif (sem == zzz) - { - }. - } - - ============ CASE 2==================== - ### ASSOCIATE CALLBACK WITH SEMAPHORE. - - sg := SemaphoreGroup with (xxx, yyy, zzz). - - oldaction := xxx signalAction: [ ... ]. ### similar interface like unix system call signal()???? method signalAction: block {} , method signalAction { ^self.signalAction } - yyy signalAction: [ ... ]. - zzz signalAction: [ ... ]. - - System signal: xxx onInput: aaa. - System signal: yyy onInput: bbb. - System signal: zzz onOutput: ccc. - - - while (true) - { - sem := sg wait. ### the action associated with the semaphore must get executed. => wait may be a primitive. the primitive handler may return failure... if so, the actual primitive body can execute the action easily - } - - - Semaphore>>method wait - { - - if (errorCode == NO ERROR) - { - self.signalAction value. ## which is better??? - self.sginalAction value: self. - } - } -*) class SemaphoreGroup(Object) diff --git a/moo/lib/exec.c b/moo/lib/exec.c index f93a778..94fc28f 100644 --- a/moo/lib/exec.c +++ b/moo/lib/exec.c @@ -1354,14 +1354,14 @@ static void signal_io_semaphore (moo_t* moo, moo_ooi_t io_handle, moo_ooi_t mask sem_io_index = moo->sem_io_map[io_handle]; - 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))) + sem = moo->sem_io_tuple[sem_io_index].sem[MOO_SEMAPHORE_IO_TYPE_OUTPUT]; + if (sem && (mask & MOO_SEMAPHORE_IO_MASK_OUTPUT)) { _signal_io_semaphore (moo, sem); } - sem = moo->sem_io_tuple[sem_io_index].sem[MOO_SEMAPHORE_IO_TYPE_OUTPUT]; - if (sem && (mask & MOO_SEMAPHORE_IO_MASK_OUTPUT)) + 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))) { _signal_io_semaphore (moo, sem); } diff --git a/moo/lib/main.c b/moo/lib/main.c index e59982e..b3ff6d8 100644 --- a/moo/lib/main.c +++ b/moo/lib/main.c @@ -1022,6 +1022,12 @@ static int _mod_poll_fd (moo_t* moo, int fd, int event_mask) MOO_ASSERT (moo, xtn->ep >= 0); memset (&ev, 0, MOO_SIZEOF(ev)); ev.events = event_mask; + #if defined(USE_THREAD) && defined(EPOLLET) + /* epoll_wait may return again if the worker thread consumes events. + * switch to level-trigger. */ + /* TODO: verify if EPOLLLET is desired */ + ev.events |= EPOLLET; + #endif ev.data.fd = fd; if (epoll_ctl (xtn->ep, EPOLL_CTL_MOD, fd, &ev) == -1) { @@ -1402,7 +1408,7 @@ static void* iothr_main (void* arg) dvp.dp_nfds = MOO_COUNTOF(xtn->ev.buf); n = ioctl (xtn->ep, DP_POLL, &dvp); #elif defined(USE_EPOLL) - n = epoll_wait (xtn->ep, xtn->ev.buf, MOO_COUNTOF(xtn->ev.buf), 10000); + n = epoll_wait (xtn->ep, xtn->ev.buf, MOO_COUNTOF(xtn->ev.buf), 10000); /* TODO: make this timeout value in the io thread */ #elif defined(USE_POLL) MUTEX_LOCK (&xtn->ev.reg.pmtx); memcpy (xtn->ev.buf, xtn->ev.reg.ptr, xtn->ev.reg.len * MOO_SIZEOF(*xtn->ev.buf));