linuxppc-dev.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
From: Arnd Bergmann <arnd.bergmann@de.ibm.com>
To: linuxppc-dev@ozlabs.org
Cc: "Thomas Klein" <tklein@de.ibm.com>,
	netdev <netdev@vger.kernel.org>,
	linux-kernel <linux-kernel@vger.kernel.org>,
	"Christoph Raisch" <raisch@de.ibm.com>,
	"Anton Blanchard" <anton@samba.org>,
	"Jörn Engel" <joern@wohnheim.fh-wedel.de>,
	"Marcus Eder" <meder@de.ibm.com>
Subject: Re: [PATCH 1/6] ehea: interface to network stack
Date: Mon, 14 Aug 2006 18:59:47 +0200	[thread overview]
Message-ID: <200608141859.48868.arnd.bergmann@de.ibm.com> (raw)
In-Reply-To: <44E09A19.9050205@de.ibm.com>

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

      reply	other threads:[~2006-08-14 16:59 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-08-09  8:38 [PATCH 1/6] ehea: interface to network stack Jan-Bernd Themann
2006-08-09  9:08 ` Christian Borntraeger
2006-08-11 11:02   ` Jan-Bernd Themann
2006-08-09 13:06 ` Alexey Dobriyan
2006-08-10 14:49   ` Jan-Bernd Themann
2006-08-10  6:15 ` Michael Ellerman
2006-08-10  7:30   ` Michael Ellerman
2006-08-10 14:28   ` Jan-Bernd Themann
2006-08-11 20:56 ` Anton Blanchard
2006-08-14 11:26   ` Jörn Engel
2006-08-14 14:38     ` Anton Blanchard
2006-08-14 15:43       ` Jan-Bernd Themann
2006-08-14 16:59         ` Arnd Bergmann [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=200608141859.48868.arnd.bergmann@de.ibm.com \
    --to=arnd.bergmann@de.ibm.com \
    --cc=anton@samba.org \
    --cc=joern@wohnheim.fh-wedel.de \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linuxppc-dev@ozlabs.org \
    --cc=meder@de.ibm.com \
    --cc=netdev@vger.kernel.org \
    --cc=raisch@de.ibm.com \
    --cc=tklein@de.ibm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).