Re: [RFC, 2.6] a simple FIFO implementation

From: Duncan Sands
Date: Fri Sep 17 2004 - 08:02:23 EST


On Friday 17 September 2004 14:48, Stelian Pop wrote:
> On Fri, Sep 17, 2004 at 02:37:57PM +0200, Duncan Sands wrote:
>
> > > + * Note that with only one concurrent reader and one concurrent
> > > + * writer, you don't need extra locking to use these functions.
> > ^^^^^ which functions? (ambiguous)
>
> Well, the same comment is for two adjacent functions, so I don't
> think it's so ambiguous. Or s/these/this/ if you prefer.
>
> > And what does "extra locking" mean?
>
> Some kind of locking, like the one the wrapper kfifo_get/kfifo_put
> propose.
>
> > > + len = min(len, fifo->size - fifo->in + fifo->out);
> >
> > After all, since you are reading both in and out here, some kind of
> > locking is needed.
>
> But the order in which in and out get modified guarantees that you
> will still have a coherent content (provided the assignments are
> atomic, which they are).

Hi Stelian, what is to stop the compiler putting, say, "in" in a register
for the process calling __kfifo_get, so that it only sees a constant
value. Then after a while that process will think there is nothing
to get even though another process is shoving stuff into the fifo and
modifying "in".

By the way, the comment for __kfifo_get has a typo:

+ * kfifo_get - gets some data from the FIFO, no locking version
^^^^^^^^^ should be __kfifo_get

Ciao,

Duncan.
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/