SELRECORD(9)

πŸ“¦ version 15.1, in freebsd 14.5, freebsd 15.1

✨ SELRECORD(9) ✨

okay so bestie, welcome to the kernel developer's manual πŸ’… this one's a 9 section page β€” that's the kernel internals zone, iykyk β€” and it's all about seldrain, selrecord, and selwakeup. these three are, like, the main character functions of the whole select/poll situation. let's get into it 🫢


✨ NAME ✨

seldrain, selrecord, selwakeup β€” record and wakeup select requests πŸŽ€


✨ SYNOPSIS ✨

#include <sys/param.h>
#include <sys/selinfo.h>

void
seldrain(struct selinfo *sip);

void
selrecord(struct thread *td, struct selinfo *sip);

void
selwakeup(struct selinfo *sip);

✨ DESCRIPTION ✨

So. seldrain(), selrecord() and selwakeup() are the three central functions used by select(2), poll(2) and the objects that are being selected on. They literally handle the whole task of recording which threads are waiting on which objects, and then waking the proper threads when an event of interest occurs on an object. no cap, that's the entire job πŸ¦‹

  • selrecord() β€” records that the calling thread is interested in events related to a given object. If another thread is already waiting on the object, a collision will be flagged in sip which will be later dealt with by selwakeup(). also, selrecord() acquires and releases sellock. slay.
  • selwakeup() β€” called by the underlying object handling code in order to notify any waiting threads that an event of interest has occurred. If a collision has occurred, selwakeup() will increment nselcoll, and broadcast on the global cv in order to wake all waiting threads so that they can handle it. If the thread waiting on the object is not currently sleeping or the wait channel is not selwait, selwakeup() will clear the TDF_SELECT flag β€” which should be noted by select(2) and poll(2) when they wake up. iconic behaviour honestly.
  • seldrain() β€” will flush the waiters queue on a specified object before its destruction. The object handling code must ensure that *sip cannot be used once seldrain() has been called. like, that pointer is done, bestie πŸ’€
The contents of *sip must be zeroed β€” such as by softc initialization β€” before any call to selrecord() or selwakeup(), otherwise a panic may occur 😭 don't skip this step fr fr.

Also: selwakeup() acquires and releases sellock and may acquire and release sched_lock. And seldrain() could usually be just a wrapper for selwakeup(), but consumers should not generally rely on this feature β€” that's a "you didn't hear it from me" situation πŸ™ˆ


✨ SEE ALSO ✨


✨ AUTHORS ✨

This manual page was written by Chad David <davidc@FreeBSD.org> and Alfred Perlstein <alfred@FreeBSD.org>. ty kings πŸ‘‘


mwah, that's a wrap! πŸ’– this little gem comes from the Debian page dated August 25, 2011 β€” oldie but a goodie, and it ate. go forth and wake your select requests responsibly, bestie 🌸✨

πŸ“¦ where this page comes from