lkml.org 
[lkml]   [2006]   [Aug]   [14]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
    /
    From
    SubjectRe: [PATCH 1/6] ehea: interface to network stack
    Date
    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@vger.kernel.org
    More majordomo info at http://vger.kernel.org/majordomo-info.html
    Please read the FAQ at http://www.tux.org/lkml/

    \
     
     \ /
      Last update: 2006-08-14 19:03    [W:4.368 / U:0.008 seconds]
    ©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site