+static int pwqr_fd_read_overcommit(int fd)
+{
+ int buf;
+
+ if (read(fd, &buf, sizeof(buf)) == sizeof(buf))
+ return buf;
+ return 0;
+}
+
+__attribute__((cold))
+static int pwqr_fd_overcommit_check(void)
+{
+ if (atomic_xchg(&pwqr_g.overcommit_count, 0)) {
+ int oc = pwqr_fd_read_overcommit(pwqr_g.fd);
+
+ if (oc) {
+ access_once(pwqr_g.overcommit_count) = (oc - 1);
+ return 1;
+ }
+ }
+ return 0;
+}
+
+__attribute__((unused))
+static void pwqr_overcommit_poll_loop(void)
+{
+ struct pollfd pfd = {
+ .fd = pwqr_g.fd,
+ .events = POLLIN,
+ };
+
+ for (;;) {
+ pfd.revents = 0;
+ if (poll(&pfd, 1, -1) >= 0) {
+ if (pfd.revents & POLLIN) {
+ access_once(pwqr_g.overcommit_count) =
+ pwqr_fd_read_overcommit(pwqr_g.fd);
+ }
+ if (pfd.revents & (POLLHUP | POLLERR))
+ return;
+ } else if (errno != EINTR && errno != EAGAIN) {
+ return;
+ }
+ }
+}
+