SELRECORD(9)

πŸ’– SELRECORD(9) πŸ’–

okay bestie, welcome to the Kernel Developer's Manual β€” this one's about seldrain, selrecord and selwakeup, aka the three functions that make select(2) and poll(2) actually work. no cap, they're kind of the main characters. πŸ‘‘


✨ 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, plus the waking of the proper threads when an event of interest occurs on an object. it's giving air traffic control but for kernel threads. ✈️

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(). drama? lowkey yes but it's handled. πŸ’…

selrecord() acquires and releases sellock. πŸ”’

selwakeup() is 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. noted, bestie. πŸ“

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, don't touch it after, fr fr.

⚠️ the contents of *sip must be zeroed, such as by softc initialization, before any call to selrecord() or selwakeup() β€” otherwise a panic may occur. not the fun kind of panic. the kernel kind. 😭 zero it first!!

selwakeup() acquires and releases sellock and may acquire and release sched_lock. seldrain() could usually be just a wrapper for selwakeup(), but consumers should not generally rely on this feature. πŸ‘€


🌈 SEE ALSO 🌈


πŸ’œ AUTHORS πŸ’œ

this manual page was written by Chad David <davidc@FreeBSD.org> and Alfred Perlstein <alfred@FreeBSD.org>. legends, honestly. πŸŽ€


and that's the whole vibe check, bestie 🧚 this page came from Debian, dated August 25, 2011 β€” stan an oldie but a goodie. now go zero your *sip before you call anything, i'm begging you πŸ™ˆπŸ’–

πŸ“¦ where this page comes from