Re: [LAD] memory allocation for the real time thread, opinions wanted

From: Fons Adriaensen <fons@email-addr-hidden>
Date: Mon Feb 27 2012 - 15:04:54 EET

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
> a method that the low prio thread is responsible for both malloc and free.

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:

---------cccccccbbbbbbbbaaaaaaa---------
         ^ ^ ^ ^
         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.

Ciao,

-- 
FA
Vor uns liegt ein weites Tal, die Sonne scheint - ein Glitzerstrahl.
_______________________________________________
Linux-audio-dev mailing list
Linux-audio-dev@email-addr-hidden
http://lists.linuxaudio.org/listinfo/linux-audio-dev
Received on Mon Feb 27 16:15:02 2012

This archive was generated by hypermail 2.1.8 : Mon Feb 27 2012 - 16:15:02 EET