Re: [PATCH 1/6] ehea: interface to network stack

From: Arnd Bergmann
Date: Mon Aug 14 2006 - 12:57:55 EST

On Monday 14 August 2006 17:43, Jan-Bernd Themann wrote:
> as our queue size is always a power of 2, we simply use:
> i++;
> i &= (ringbufferlength - 1)
> So we can get along without the if.

The recommended (by Linus) way for dealing with ring buffers
like that is to always read the counter through an accessor
and don't care about the overflow when updating it.

You can write small access functions for that:

struct my_struct {
unsigned rbuf_index;
unsigned rbuf_mask;

static inline unsigned int my_index(struct my_struct *p)
return p->rb_index & p->rb_mask;

static inline unsigned int my_index_next(struct my_struct *p)
return (++p->rb_index) & p->rb_mask;

Arnd <><
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at
Please read the FAQ at