diff --git a/io/epoll.cpp b/io/epoll.cpp index ec8a3fa7..e3ffdedb 100644 --- a/io/epoll.cpp +++ b/io/epoll.cpp @@ -302,26 +302,6 @@ ok: entry.interests |= eint; thread* current = CURRENT; int ret = add_interest({fd, interest | ONE_SHOT, current}); if (ret < 0) LOG_ERROR_RETURN(0, -1, "failed to add event interest"); - // if timeout is just simple 0, wait for a tiny little moment - // so that events can be collect. - if (timeout.expired()) { - ret = -1; - wait_for_events( - 0, - [current, &ret](void* data) __INLINE__ { - if ((thread*)data == current) { - ret = 0; - } else { - thread_interrupt((thread*)data, EOK); - } - }, - [&]() __INLINE__ { return true; }); - if (ret < 0) { - rm_interest({fd, interest, 0}); - errno = ETIMEDOUT; - } - return ret; - } ret = thread_usleep(timeout); ERRNO err; if (ret == -1 && err.no == EOK) { diff --git a/io/kqueue.cpp b/io/kqueue.cpp index 90b60659..8f103946 100644 --- a/io/kqueue.cpp +++ b/io/kqueue.cpp @@ -122,20 +122,6 @@ class KQueue : public MasterEventEngine, public CascadingEventEngine, public Res auto current = CURRENT; int ret = enqueue(fd, ev, EV_ADD | EV_ONESHOT, 0, current); if (ret < 0) return ret; - if (timeout.expired()) { - ret = -1; - do_wait_and_fire_events(0, [current, &ret](thread* th) { - if (th == current) - ret = 0; - else - thread_interrupt(th, EOK); - }); - if (ret <0) { - enqueue(fd, ev, EV_DELETE, 0, current, true); - errno = ETIMEDOUT; - } - return ret; - } ret = thread_usleep(timeout); ERRNO err; if (ret == -1 && err.no == EOK) { @@ -152,8 +138,13 @@ class KQueue : public MasterEventEngine, public CascadingEventEngine, public Res } int cancel_wait() override { - enqueue(_kq, EVFILT_USER, EV_ONESHOT, NOTE_TRIGGER, nullptr, true); - return 0; + // cannot call `enqueue` directly since it will be called from another vCPU. + // directly use kqueue to submit event, which is safe. + // as same as `enqueue(_kq, EVFILT_USER, EV_ONESHOT, NOTE_TRIGGER, nullptr, true)` + struct kevent entry; + EV_SET(&entry, _kq, EVFILT_USER, EV_ONESHOT, NOTE_TRIGGER, 0, nullptr); + struct timespec tm{0, 0}; + return kevent(_kq, _events, _n, nullptr, 0, &tm); } // This vector is used to filter invalid add/rm_interest requests which may affect kevent's