Simplified, I wanted this:
if (kn->kn_filter == EVFILT_READ) {
kn->kn_data = sndbuf_getready(ch->bufsoft);
kn->kn_kevent.ext[0] = sndbuf_getfreeptr(ch->bufsoft);
} else {
kn->kn_data = sndbuf_getfree(ch->bufsoft);
kn->kn_kevent.ext[0] = sndbuf_getreadyptr(ch->bufsoft);
}
kn->kn_kevent.ext[1] = ch->xruns;But that introduces deadlock hence the rest of the kernel side patch. The example is changed so it reflects the new change. Rationale for this is that in real-time audio applications, code will always use mmap'ed device access and do this in a loop:
- calculate wait time (or use kqueue for waiting)
- use ioctl for SNDCTL_DSP_GETIPTR (or GETOPTR for playback) to get the pointer into the memory-mapped buffer where new data starts
- use ioctl for SNDCTL_DSP_GETERROR to get xruns and handle them
With this patch, all the info is returned to user space in one syscall, reducing CPU churn and processing time, which is critical for real-time applications. For non-mmaped access, SNDCTL_DSP_CURRENT_IPTR is returned instead of SNDCTL_DSP_GETIPTR in ext[0].