Consolidate to a single posix ticker implementation

Following on from MR !15757 (closed) which removed the two signal based ticker implementations, combine the two remaining posix ticker implementations into a single portable one.

The two existing ones:

  1. based on pthreads and nanosleep: a thread waits using nanosleep; and one
  2. based on pthreads and timerfd: a thread waits (using poll) on two fds, one for the timerfd and one for prompt interrupt for shutdown.

We combine these into a single one:

  • based on pthreads and select/ppoll: a thread waits using select/ppoll on a timeout and an fd for prompt interrupt for shutdown.

There appears to be no great advantage on Linux to using timerfd rather than just using select/ppoll with a timeout. We are always using relative timeouts, so we don't need the features that timerfd provides.

The two ticker impls were already very close. The timerfd one had clearly been implemented by copying and modifying the pthreads one.

So all we need to do is extend the existing pthread ticker implementation with a mechanism for prompt wakeup, like the timerfd one has. Rather than just copying the pipe code used in the timerfd impl, we add a new utility module FdWakeup.{c,h} which captures the self-pipe trick, but also has an alternative implementation using eventfd which uses fewer resources (on supported platforms). We use select or ppoll, not poll, since poll does not provide the timeout precision that we need. A test program indicates that there's no significant difference to the wakeup lag of nanosleep vs select or ppoll.

Merge request reports

Loading