[Git][ghc/ghc][wip/dcoutts/issue-27105-stopTicker] FIXUP: posix ticker, fix logic when using select()
Duncan Coutts pushed to branch wip/dcoutts/issue-27105-stopTicker at Glasgow Haskell Compiler / GHC Commits: 8f58e22a by Duncan Coutts at 2026-06-12T15:50:56+01:00 FIXUP: posix ticker, fix logic when using select() This is why the OSX CI was hanging, it was the only platform using select, Linux and all the BSDs were using ppoll. TODO: squash this into "posix ticker: split out ppoll/select helper functions" though actually the bug seems to be already prior to that version, so unclear how this was working. - - - - - 1 changed file: - rts/posix/Ticker.c Changes: ===================================== rts/posix/Ticker.c ===================================== @@ -317,14 +317,23 @@ static void poll_init_timeout(timeout *tv, Time t) static void poll_init_fdset(fdset *fds, int fd) { - /* select() overwrites the fdset so we must rebuild it every time. */ - FD_ZERO(&fds->selectfds); - FD_SET(fd, &fds->selectfds); + /* select() modifies the fd_set: it uses the same fd_set for reporting as + * for input. Thus we must rebuild it every time. We can optimise this + * rebuilding somewhat however if we rely on select() not modifying the + * bits that we didn't ask it to look at. So we can zero the fd_set just + * once, and then only reset the single bit for the single fd, before each + * call to selct(). + */ fds->fd = fd; + FD_ZERO(&fds->selectfds); } static int poll_no_timeout(fdset *fds) { + /* select() modifies the fd_set so we must set it every time, but we rely + * on it not touching other bits to avoid having to FD_ZERO it every time + */ + FD_SET(fds->fd, &fds->selectfds); int nfds = fds->fd+1; return select(nfds, &fds->selectfds, NULL, NULL, NULL); } @@ -332,6 +341,10 @@ static int poll_no_timeout(fdset *fds) static int poll_with_timeout(fdset *fds, timeout *tv) { struct timeval tv_tmp = *tv; // copy since select may change this value. + /* select() modifies the fd_set so we must set it every time, but we rely + * on it not touching other bits to avoid having to FD_ZERO it every time + */ + FD_SET(fds->fd, &fds->selectfds); int nfds = fds->fd+1; return select(nfds, &fds->selectfds, NULL, NULL, &tv_tmp); } View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/8f58e22a271d5d20b7c06d3bc9033280... -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/8f58e22a271d5d20b7c06d3bc9033280... You're receiving this email because of your account on gitlab.haskell.org.
participants (1)
-
Duncan Coutts (@dcoutts)