Source-Changes-D archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: CVS commit: src/sys/arch/xen/xen



Hello,

"Jean-Yves Migeon" <jym%netbsd.org@localhost> wrote:
> Module Name:  src
> Committed By: jym
> Date:         Sun May 15 07:24:15 UTC 2011
> 
> Modified Files:
>       src/sys/arch/xen/xen: xbdback_xenbus.c
> 
> Log Message:
> Use atomic_ops(3) for ref counting.
> 

> +       atomic_dec_uint(&(xbdip)->xbdi_refcnt);              \
> +       if (0 == (xbdip)->xbdi_refcnt)                       \
>                 xbdback_finish_disconnect(xbdip);             \

This is not correct.  Atomic op might decrease the reference count to
1 while other thread executes xbdi_put() before xbdi_refcnt is fetched,
thus decreasing it to 0.  In such case, both threads would fetch 0.

The following is a correct way:

        if (atomic_dec_uint_nv(&xbdip->xbdi_refcnt) == 0)
                xbdback_finish_disconnect(xbdip);

Also, it seems there is no need for xbdi_refcnt to be volatile.

-- 
Mindaugas


Home | Main Index | Thread Index | Old Index