On Mon, Feb 27, 2012 at 09:59:19AM +0100, Nick Copeland wrote:
> Both of these methods are affectively the same, what you are trying to do is provide
That's a nice method, it effectively uses the LFQ to 'send back' an item after
use by the recipient. It depends on the particular implementation of the queue,
you need one that allows to read one (or more if necessary) items without moving
the read pointer - that should be done only after the data has been used since
it signals that the data can be freed.
The alternative is to make this explicit, by having two pairs of indices
operate on the same buffer:
^ ^ ^ ^
R2 W2 R1 W1
W1 and R1 are the usual W/R indices, assume they increment whenever
an item is written or read. The 'aaaaa' are items sent by the low-prio
thread but not yet received by the RT one.
W2 is incremented by the RT thread whenever it's done with an item
(this is a 'write' operation, but no data transfer is necessary).
The 'bbbbbb' are items currently being used by the RT thread.
R2 is used by the low-prio thread to 'read' items that can be freed
or re-used (the 'ccccccc').
In fact this can be generalised to support any linear chain of threads
operating sequentially on the same data, just use as many R/W pairs as
there are threads. As long as there is only one thread modifying each
index and only one other thread reading it, it can still be lock-free.
Vor uns liegt ein weites Tal, die Sonne scheint - ein Glitzerstrahl.
Linux-audio-dev mailing list