Re: [RFC, 2.6] a simple FIFO implementation

From: Stelian Pop
Date: Thu Sep 16 2004 - 11:11:44 EST


On Thu, Sep 16, 2004 at 08:45:49AM -0700, Paul Jackson wrote:

> > 'size' field instead of an 'end'
>
> The start, end, put, get names in that *.pdf might be a
> bit quicker to read.
>
> I suspect that more readers would come away with the right
> understanding, first time, if you struct was (taken roughly
> from the *.pdf, using an 'end' one bigger than *.pdf uses):
>
> /* kfifo is empty, not full, when head == tail */
> struct kfifo {
> unsigned char *start; /* [start, end) */
> unsigned char *end;
> unsigned char *head; /* next input char goes in here */
> unsigned char *tail; /* next output char comes from here */
> spinlock_t lock;
> };
>
> then your structure:
>
> struct kfifo {
> unsigned int head;
> unsigned int tail;
> unsigned int size;
> spinlock_t lock;
> unsigned char *buffer;
> };
>
> Differences include names, all pointers,

Except that this implementation requires 'head' and 'tail' to be
constrained to be between 'start' and 'end', adding an if test instead
of arithmetic unsigned int wrap.

> ordering of struct elements,

I could place buffer at the beginning of the struct, indeed.

> and comments.

And commenting the fields is of course a very good idea.

Stelian.
--
Stelian Pop <stelian@xxxxxxxxxx>
-
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/