On Sun, Aug 19, 2012 at 12:35:21PM +0200, Marc Espie wrote:
> Is there any actual reason for these restrictions ?
>
> I can understanding preventing stuff if it breaks, but I don't think
> it does ?
>
Actually most of these are not restrictions but assertions to force
incorrect programs to fail rather than letting them work badly.
> Index: sio.c
> ===================================================================
> RCS file: /home/openbsd/cvs/src/lib/libsndio/sio.c,v
> retrieving revision 1.10
> diff -u -p -r1.10 sio.c
> --- sio.c 23 May 2012 19:25:11 -0000 1.10
> +++ sio.c 19 Aug 2012 10:32:53 -0000
> @@ -174,11 +174,6 @@ sio_getpar(struct sio_hdl *hdl, struct s
> DPRINTF("sio_getpar: eof\n");
> return 0;
> }
> - if (hdl->started) {
> - DPRINTF("sio_getpar: already started\n");
> - hdl->eof = 1;
> - return 0;
> - }
> if (!hdl->ops->getpar(hdl, par)) {
> par->__magic = 0;
> return 0;
FWIW, allowing sio_getpar() won't work; and even if it worked the
program wouldn't work very well since sio_getpar() is blocking,
while the promise is that sndio doesn't block.
> @@ -385,11 +380,6 @@ sio_eof(struct sio_hdl *hdl)
> void
> sio_onmove(struct sio_hdl *hdl, void (*cb)(void *, int), void *addr)
> {
> - if (hdl->started) {
> - DPRINTF("sio_onmove: already started\n");
> - hdl->eof = 1;
> - return;
> - }
> hdl->move_cb = cb;
> hdl->move_addr = addr;
> }
> @@ -437,11 +427,6 @@ sio_setvol(struct sio_hdl *hdl, unsigned
> int
> sio_onvol(struct sio_hdl *hdl, void (*cb)(void *, unsigned int), void *addr)
> {
> - if (hdl->started) {
> - DPRINTF("sio_onvol: already started\n");
> - hdl->eof = 1;
> - return 0;
> - }
> if (!hdl->ops->setvol)
> return 0;
> hdl->vol_cb = cb;
Technically sio_onmove() and sio_onvol() can be called after DMA is
started, but it would be a mistake in 90% of the cases. It's
somewhat like establishing an interrupt in a driver after the
device is started. Or like changing SIGALRM handler while the timer
is running.
If you're writing code that needs sio_onmove() and sio_onvol() to
be called during DMA, then remove below asserts.
-- Alexandre