Browse Source

[core] perf: pass (fdnode *) to epoll and kqueue

personal/stbuehler/ci-build
Glenn Strauss 3 years ago
parent
commit
d76756ca10
  1. 1
      src/fdevent.c
  2. 16
      src/fdevent_freebsd_kqueue.c
  3. 6
      src/fdevent_linux_sysepoll.c

1
src/fdevent.c

@ -302,6 +302,7 @@ void fdevent_sched_close(fdevents *ev, int fd, int issock) {
fdnode *fdn = ev->fdarray[fd];
if ((uintptr_t)fdn & 0x3) return;
ev->fdarray[fd] = (fdnode *)((uintptr_t)fdn | (issock ? 0x1 : 0x2));
fdn->handler = (fdevent_handler)NULL;
fdn->ctx = ev->pendclose;
ev->pendclose = fdn;
}

16
src/fdevent_freebsd_kqueue.c

@ -28,11 +28,11 @@ static int fdevent_freebsd_kqueue_event_del(fdevents *ev, fdnode *fdn) {
int oevents = fdn->events;
if (oevents & FDEVENT_IN) {
EV_SET(&kev[n], fd, EVFILT_READ, EV_DELETE, 0, 0, NULL);
EV_SET(&kev[n], fd, EVFILT_READ, EV_DELETE, 0, 0, fdn);
n++;
}
if (oevents & FDEVENT_OUT) {
EV_SET(&kev[n], fd, EVFILT_WRITE, EV_DELETE, 0, 0, NULL);
EV_SET(&kev[n], fd, EVFILT_WRITE, EV_DELETE, 0, 0, fdn);
n++;
}
@ -49,17 +49,17 @@ static int fdevent_freebsd_kqueue_event_set(fdevents *ev, fdnode *fdn, int event
int delevents = ~events & oevents;
if (addevents & FDEVENT_IN) {
EV_SET(&kev[n], fd, EVFILT_READ, EV_ADD, 0, 0, NULL);
EV_SET(&kev[n], fd, EVFILT_READ, EV_ADD, 0, 0, fdn);
n++;
} else if (delevents & FDEVENT_IN) {
EV_SET(&kev[n], fd, EVFILT_READ, EV_DELETE, 0, 0, NULL);
EV_SET(&kev[n], fd, EVFILT_READ, EV_DELETE, 0, 0, fdn);
n++;
}
if (addevents & FDEVENT_OUT) {
EV_SET(&kev[n], fd, EVFILT_WRITE, EV_ADD, 0, 0, NULL);
EV_SET(&kev[n], fd, EVFILT_WRITE, EV_ADD, 0, 0, fdn);
n++;
} else if (delevents & FDEVENT_OUT) {
EV_SET(&kev[n], fd, EVFILT_WRITE, EV_DELETE, 0, 0, NULL);
EV_SET(&kev[n], fd, EVFILT_WRITE, EV_DELETE, 0, 0, fdn);
n++;
}
@ -77,10 +77,10 @@ static int fdevent_freebsd_kqueue_poll(fdevents * const ev, int timeout_ms) {
n = kevent(ev->kq_fd, NULL, 0, ev->kq_results, ev->maxfds, &ts);
for (int i = 0; i < n; ++i) {
fdnode * const fdn = ev->fdarray[ev->kq_results[i].ident];
fdnode * const fdn = (fdnode *)ev->kq_results[i].udata;
int filt = ev->kq_results[i].filter;
int e = ev->kq_results[i].flags;
if (0 == ((uintptr_t)fdn & 0x3)) {
if ((fdevent_handler)NULL != fdn->handler) {
int revents = (filt == EVFILT_READ) ? FDEVENT_IN : FDEVENT_OUT;
if (e & EV_EOF)
revents |= (filt == EVFILT_READ ? FDEVENT_RDHUP : FDEVENT_HUP);

6
src/fdevent_linux_sysepoll.c

@ -27,7 +27,7 @@ static int fdevent_linux_sysepoll_event_set(fdevents *ev, fdnode *fdn, int event
int fd = fdn->fde_ndx = fdn->fd;
struct epoll_event ep;
ep.events = events | EPOLLERR | EPOLLHUP;
ep.data.fd = fd;
ep.data.ptr = fdn;
return epoll_ctl(ev->epoll_fd, op, fd, &ep);
}
@ -35,9 +35,9 @@ static int fdevent_linux_sysepoll_poll(fdevents * const ev, int timeout_ms) {
int n = epoll_wait(ev->epoll_fd, ev->epoll_events, ev->maxfds, timeout_ms);
server * const srv = ev->srv;
for (int i = 0; i < n; ++i) {
fdnode * const fdn = ev->fdarray[ev->epoll_events[i].data.fd];
fdnode * const fdn = (fdnode *)ev->epoll_events[i].data.ptr;
int revents = ev->epoll_events[i].events;
if (0 == ((uintptr_t)fdn & 0x3)) {
if ((fdevent_handler)NULL != fdn->handler) {
(*fdn->handler)(srv, fdn->ctx, revents);
}
}

Loading…
Cancel
Save