Thread (13 messages) flat view 13 messages, 7 authors, 2006-08-14

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

From: Arnd Bergmann <hidden>
Date: 2006-08-14 16:59:58
Also in: lkml, netdev

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 <><
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help