[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Date: Thu, 9 Sep 2010 17:38:07 +0200
From: Jarek Poplawski <jarkao2@...il.com>
To: Eric Dumazet <eric.dumazet@...il.com>
Cc: David Miller <davem@...emloft.net>, jesse@...ira.com,
netdev@...r.kernel.org
Subject: Re: [PATCH net-next-2.6] net: inet_add_protocol() can use cmpxchg()
On Thu, Sep 09, 2010 at 02:57:38PM +0200, Eric Dumazet wrote:
> Le jeudi 09 septembre 2010 ?? 09:59 +0000, Jarek Poplawski a écrit :
>
> > Btw, I wonder if for readability and debuging it shouldn't be made
> > generic as rcu_cmpxchg_pointer() etc.?
>
> There are a lot of things to do in this area (with proper __rcu sparse
> annotations, this can be not very readable ...)
Well, this is more than I could dream ;-) The main point to me was
autodocumentation in use, similarly to rcu_assign_pointer(). But, of
course, with the description below it's much better.
Thanks,
Jarek P.
>
> /**
> * rcu_cmpxchg - atomic compare and exchange, SMP & rcu safe
> * @p: pointer to value
> * @old: old value
> * @new: new value
> *
> * Equivalent to :
> * ATOMIC_BEGIN
> * ret = *p;
> * if (ret == old)
> * rcu_assign_pointer(*p, new);
> * ATOMIC_END
> * return ret;
> *
> * cmpxpchg() contains full memory barriers, so can be used
> * in rcu write side without additional smp_wmb() barrier
> */
> #define rcu_cmpxchg(p, old, new) cmpxchg(p, old, new)
>
>
> const struct net_protocol __rcu *
> inet_protos[MAX_INET_PROTOS] __read_mostly;
>
> ...
>
> return !rcu_cmpxchg(&inet_protos[hash],
> NULL,
> (const struct net_protocol __force __rcu *)prot) ?
> 0 : -1;
>
> ...
>
--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Powered by blists - more mailing lists