[Jack-Devel] buffer size callback, revisit

PrevNext  Index
DateTue, 15 Feb 2011 12:21:26 -0500
From Paul Davis <[hidden] at linuxaudiosystems dot com>
ToJACK <[hidden] at lists dot jackaudio dot org>
Follow-UpJack O'Quin Re: [Jack-Devel] buffer size callback, revisit
(this message mostly reiterates something that torben bought up the other day).

there is a potential race condition in the way that current JACK
implementations make the port buffer sizes available to clients. the
simplest way to visualize the problem is something like this:

  CLIENT:
	    jack_client_t* jack_client = jack_client_open (...);
            size_t sz = jack_get_buffer_size (jack_client);
	    ptr = malloc (sz);
            ....
                                                                  OTHER CLIENT

jack_set_buffer_size (jack_client, nframes);
            ....
            jack_activate (jack_client)

once CLIENT gets a process callback that uses "ptr" as a pointer to
some memory, it won't know that the buffer is the wrong size.

this is true EVEN IF the client registered a buffer size callback. why
so? despite the suggestion in the API docs for the buffer size
callback, existing implementations do NOT guarantee to call the
client's buffer size callback from within jack_activate(). this means
that there is no reliable way for a client to know the port buffer
size before its first process callback. the buffer size callback will
notify it of later changes to the size, but not the initial size when
it gets its first process() call.

torben and i have discussed this and although we came up with some
less intrusive/changy schemes, they are all wrong at a fundamental
level. what we propose is a subtle change that unfortunately requires
a new API call.

what we believe is the right approach to fixing this has 3 parts:

   1) a new buffer size callback that can be registered with the
explicit understanding that it will be called from any subsequent call
to jack_activate() (if there is one)
   2) JACK implementations change to honor (1)
   3) a new function, jack_get_buffer_size_by_type() which will return
the size, in bytes, of the port buffers associated with a particular
buffer type

in association with this, we would mark jack_get_buffer_size() and the
old buffer size callback registration functions as deprecated.

its unfortunate to have to make such a "deep" change to fix an
apparently "minor" race condition, but the semantics in the current
API are really genuinely incorrect and always have been.

comments welcome, as usual. lets not hear from all the same people :))

--p
PrevNext  Index

1297790510.22481_0.ltw:2,a <AANLkTi=2BP6veaaCtmjG6FnAz=uufCww1F3DBpp41PBK at mail dot gmail dot com>