[openib-general] Re: [PATCH] cm refcount race fix

Michael S. Tsirkin mst at mellanox.co.il
Mon May 8 09:46:54 PDT 2006


Quoting r. Roland Dreier <rdreier at cisco.com>:
> Subject: Re: [PATCH] cm refcount race fix
> 
> Good idea.  I think with
> 
> static inline int get_obj_refcount(struct foo *obj)
> {
>         int c;
> 
>         spin_lock_irq(&obj->lock);
>         c = obj->refcount;
>         spin_unlock_irq(&obj->lock);
> 
>         return c;
> }
> 
> then
> 
> 	wait_event(&obj->wait, !get_obj_refcount(&obj));
> 
> looks like a pretty clean solution.

Right, fine, but if we change refcount from atomic to int,
we still need to edit all code and replace
atomic_inc/atomic_dec with lock/modify/unlock.

Would 

static inline int get_obj_refcount(struct foo *obj)
{
        int c;

        spin_lock_irq(&obj->lock);
        c = atomic_read(&obj->refcount);
        spin_unlock_irq(&obj->lock);

        return c;
}

be acceptable?

-- 
MST



More information about the general mailing list