Thread (4 messages) 4 messages, 3 authors, 2002-06-19

Re: kfree_skb: unnecessary check ?

From: <hidden>
Date: 2002-06-19 20:26:30

Hello!
Is atomic_dec_and_test really necessary ? atomic_dec_and_test only 
returns true if its argument has hit zero, so it was 1 before.
If atomic_dec is only a bit cheaper than atomic_dec_and_test (which i 
guess it is), wouldn't it make more sense to use something like this:
Does the prefix "atomic" not scare you? :-)

static inline void kfree_skb(struct sk_buff *skb)
{
    if (atomic_read(&skb->users) == 1)
        __kfree(skb);
    else
        atomic_dec(&skb->users);
}
      else if (atomic_dec_and_test(&skb->users))
	   __kfree_skb(skb);

If you still do not understand think why it does not look like:

static inline void kfree_skb(struct sk_buff *skb)
{
    int users = skb->users;
    if (users == 1)
        __kfree(skb);
    else
        skb->users = users - 1;
}

Alexey
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help