Re: [linux-audio-dev] jack_callback <-> rest of the world

From: Lars Luthman <larsl@email-addr-hidden>
Date: Sun Oct 30 2005 - 03:03:04 EEST

On Sun, 2005-10-30 at 00:42 +0200, Richard Spindler wrote:
> I have two questions concerning the jack callback,
>
> 1. what is the preferred way of feeding data from disk to the callback?
>
> Is there a general design pattern agreed upon? Best Practices?

The most common way is to use some variant of a non-blocking ringbuffer.
The JACK library has a ringbuffer that you can use for this, see
http://jackit.sourceforge.net/docs/reference/html/ringbuffer_8h.html

> 2. What is the preferred way to notify the non-realtime thread that
> something happened in the jack-callback?

It depends on how detailed information you want in the non-RT thread. If
you just want to say "something happened!" you can use a counter of a
datatype that you know is read and written atomically (int usually
works) and increase it every time something happens. The non-RT thread
can then compare the counter's value to the value it had last time it
looked at it, and if it's different it knows that something has
happened. If you need to more detailed information you can define a
message struct or enum and use a ringbuffer of the same type as above to
send those messages to the non-RT thread.

> I read the tutorial at http://userpages.umbc.edu/~berman3/ , it uses
> mutex+condition, is it okay to do this? Are there better ways?

Locking a mutex in the process callback is usually not considered OK for
a JACK program that is meant to run in realtime, because it can yield
the CPU to some other process or thread while waiting for the mutex,
which can cause unneccessary xruns.

-- 
Lars Luthman
PGP key:     http://www.d.kth.se/~d00-llu/pgp_key.php
Fingerprint: FCA7 C790 19B9 322D EB7A  E1B3 4371 4650 04C7 7E2E

Received on Sun Oct 30 04:15:08 2005

This archive was generated by hypermail 2.1.8 : Sun Oct 30 2005 - 04:15:09 EET