Re: [LAD] [LAU] Simple, easy multithreaded circular buffer library for Linux?

From: Fons Adriaensen <fons@email-addr-hidden>
Date: Sun Oct 19 2008 - 12:13:58 EEST

On Sun, Oct 19, 2008 at 09:55:54AM +0200, Paul Davis wrote:

> 1) fons' design, which never actually wraps readptr or writeptr, but
> masks the address used to access the data buffer
>
> 2) removing the intermediate state's visibility
>
> i admit to preferring (2) even though i know that with a 64 bit index,
> not wrapping the ptrs is not really a problem.

Another advantage of 1 is that it has no problem with
a completely full buffer, and this doesn't even require
any special code. If access is always in 2^N blocks,
it can store one block more.

> i think that the simpler code:
>
> ptr = (ptr + incr) & mask;
>
> is subject to potential compiler and/or processor "optimization" that
> might reduce it back to the problem case of two ops without an
> intermediate load/store location.

You mean _with_ and intermediate store (I hope) ?

Adding a intermediate store would not really be an
'optimisation'... I doubt if any compiler would do
it. But you can prevent it from doing so, see below.

> the volatile declaration ought to prevent the compiler from
> doing this

It does. Declaring a var volatile means that the compiler MUST
assume that reading or writing it can have side effects, and
that therefore it MUST access the var exactly as specified. For
the new code this means that only the correct value will ever
be written, for the old it forced the compiler to write the
wrong one.

Ciao,

-- 
FA
Laboratorio di Acustica ed Elettroacustica
Parma, Italia
Lascia la spina, cogli la rosa.
_______________________________________________
Linux-audio-dev mailing list
Linux-audio-dev@email-addr-hidden
http://lists.linuxaudio.org/mailman/listinfo/linux-audio-dev
Received on Sun Oct 19 16:15:01 2008

This archive was generated by hypermail 2.1.8 : Sun Oct 19 2008 - 16:15:02 EEST