Skip to content

Commit

Permalink
Since now thread_usleep(0) can also bring errno of interruption, it s…
Browse files Browse the repository at this point in the history
…hould be working
  • Loading branch information
Coldwings committed Sep 18, 2024
1 parent 7706ac7 commit f815964
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 36 deletions.
20 changes: 0 additions & 20 deletions io/epoll.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
23 changes: 7 additions & 16 deletions io/kqueue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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
Expand Down

0 comments on commit f815964

Please sign in to comment.