mirror of
https://github.com/Mathewnd/Astral.git
synced 2026-11-01 06:58:22 +00:00
mlibc sysdeps: rewrite a chunk of pselect to be faster
This commit is contained in:
@@ -360,10 +360,10 @@ index 0000000..e5b087a
|
|||||||
+
|
+
|
||||||
diff --git mlibc-workdir/sysdeps/astral/generic/generic.cpp mlibc-workdir/sysdeps/astral/generic/generic.cpp
|
diff --git mlibc-workdir/sysdeps/astral/generic/generic.cpp mlibc-workdir/sysdeps/astral/generic/generic.cpp
|
||||||
new file mode 100644
|
new file mode 100644
|
||||||
index 0000000..afaee81
|
index 0000000..6ece9e1
|
||||||
--- /dev/null
|
--- /dev/null
|
||||||
+++ mlibc-workdir/sysdeps/astral/generic/generic.cpp
|
+++ mlibc-workdir/sysdeps/astral/generic/generic.cpp
|
||||||
@@ -0,0 +1,634 @@
|
@@ -0,0 +1,652 @@
|
||||||
+#include <bits/ensure.h>
|
+#include <bits/ensure.h>
|
||||||
+#include <mlibc/debug.hpp>
|
+#include <mlibc/debug.hpp>
|
||||||
+#include <mlibc/all-sysdeps.hpp>
|
+#include <mlibc/all-sysdeps.hpp>
|
||||||
@@ -670,8 +670,10 @@ index 0000000..afaee81
|
|||||||
+ if(fds == NULL)
|
+ if(fds == NULL)
|
||||||
+ return ENOMEM;
|
+ return ENOMEM;
|
||||||
+
|
+
|
||||||
|
+ int actualcount = 0;
|
||||||
|
+
|
||||||
+ for (int fd = 0; fd < num_fds; ++fd) {
|
+ for (int fd = 0; fd < num_fds; ++fd) {
|
||||||
+ short events;
|
+ short events = 0;
|
||||||
+ if (read_set && FD_ISSET(fd, read_set)) {
|
+ if (read_set && FD_ISSET(fd, read_set)) {
|
||||||
+ events |= POLLIN;
|
+ events |= POLLIN;
|
||||||
+ }
|
+ }
|
||||||
@@ -685,34 +687,50 @@ index 0000000..afaee81
|
|||||||
+ }
|
+ }
|
||||||
+
|
+
|
||||||
+ if (events) {
|
+ if (events) {
|
||||||
+ fds[fd].fd = fd;
|
+ fds[actualcount].fd = fd;
|
||||||
+ fds[fd].events = events;
|
+ fds[actualcount].events = events;
|
||||||
+ fds[fd].revents = 0;
|
+ fds[actualcount].revents = 0;
|
||||||
+ } else {
|
+ actualcount++;
|
||||||
+ fds[fd].fd = -1;
|
|
||||||
+ }
|
+ }
|
||||||
+ }
|
+ }
|
||||||
+
|
+
|
||||||
+ int time = timeout == NULL ? -1 : timeout->tv_sec * 1000 + timeout->tv_nsec / 1000000;
|
+ int time = timeout == NULL ? -1 : timeout->tv_sec * 1000 + timeout->tv_nsec / 1000000;
|
||||||
+
|
+
|
||||||
+ int err = sys_poll(fds, num_fds, time, num_events);
|
+ int num;
|
||||||
|
+ int err = sys_poll(fds, actualcount, time, &num);
|
||||||
+
|
+
|
||||||
+ if (err) {
|
+ if (err) {
|
||||||
+ free(fds);
|
+ free(fds);
|
||||||
+ return err;
|
+ return err;
|
||||||
+ }
|
+ }
|
||||||
+
|
+
|
||||||
+ for (int fd = 0; fd < num_fds; ++fd) {
|
+ #define READ_SET_POLLSTUFF (POLLIN | POLLHUP | POLLERR)
|
||||||
+ if (read_set && (fds[fd].revents & POLLIN) == 0)
|
+ #define WRITE_SET_POLLSTUFF (POLLOUT | POLLERR)
|
||||||
+ FD_CLR(fd, read_set);
|
+ #define EXCEPT_SET_POLLSTUFF (POLLPRI)
|
||||||
+
|
+
|
||||||
+ if (write_set && (fds[fd].revents & POLLOUT) == 0)
|
+ int returncount = 0;
|
||||||
+ FD_CLR(fd, write_set);
|
+ for (int fd = 0; fd < actualcount; ++fd) {
|
||||||
|
+ int events = fds[fd].events;
|
||||||
|
+ if ((events & POLLIN) && (fds[fd].revents & READ_SET_POLLSTUFF) == 0) {
|
||||||
|
+ FD_CLR(fds[fd].fd, read_set);
|
||||||
|
+ events &= ~POLLIN;
|
||||||
|
+ }
|
||||||
+
|
+
|
||||||
+ if (except_set && (fds[fd].revents & POLLPRI) == 0)
|
+ if ((events & POLLOUT) && (fds[fd].revents & WRITE_SET_POLLSTUFF) == 0) {
|
||||||
+ FD_CLR(fd, except_set);
|
+ FD_CLR(fds[fd].fd, write_set);
|
||||||
|
+ events &= ~POLLOUT;
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ if ((events & POLLPRI) && (fds[fd].revents & EXCEPT_SET_POLLSTUFF) == 0) {
|
||||||
|
+ FD_CLR(fds[fd].fd, except_set);
|
||||||
|
+ events &= ~POLLPRI;
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ if (events)
|
||||||
|
+ returncount++;
|
||||||
+ }
|
+ }
|
||||||
+
|
+ *num_events = returncount;
|
||||||
|
+ free(fds);
|
||||||
+ return 0;
|
+ return 0;
|
||||||
+ }
|
+ }
|
||||||
+#endif
|
+#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user