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

Arnd Bergmann arnd.bergmann at de.ibm.com
Tue Aug 15 02:59:47 EST 2006

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 <><

More information about the Linuxppc-dev mailing list