Expand description
Eventfd based implementation of the ping event source.
Β§Implementation notes
The eventfd is a much lighter signalling mechanism provided by the Linux kernel. Rather than write an arbitrary sequence of bytes, it only has a 64-bit counter.
To avoid closing the eventfd early, we wrap it in a RAII-style closer
CloseOnDrop
in make_ping()
. When all the senders are dropped, another
wrapper FlagOnDrop
handles signalling this to the event source, which is
the sole owner of the eventfd itself. The senders have weak references to
the eventfd, and if the source is dropped before the senders, they will
simply not do anything (except log a message).
To differentiate between regular ping events and close ping events, we add 2 to the counter for regular events and 1 for close events. In the source we can then check the LSB and if itβs set, we know it was a close event. This only works if a close event never fires more than once.
Structs§
- ArcAsFd π
- FlagOnDrop πThis manages signalling to the PingSource when itβs dropped. There should only ever be one of these per PingSource.
Constants§
- INCREMENT_CLOSE π
- INCREMENT_PING π
Functions§
- drain_ping π
- send_ping π