[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] Re: [Xen-devel] [PATCH v2 2/3] xen/atomic: Implement atomic_{inc, dec}_bounded()
>>> On 02.07.14 at 15:47, <andrew.cooper3@xxxxxxxxxx> wrote: > These will increment/decremented an atomic_t, while ensuring that the > atomic_t > doesn't hit a specific bound. > > This involves introducing atomic_cmpxchg() for x86, which previously only > existed on ARM. > > Suggested-by: Don Slutz <dslutz@xxxxxxxxxxx> > Signed-off-by: Andrew Cooper <andrew.cooper3@xxxxxxxxxx> > CC: Keir Fraser <keir@xxxxxxx> > CC: Jan Beulich <JBeulich@xxxxxxxx> You should be getting used to Cc all "REST" maintainers on respective changes. > --- /dev/null > +++ b/xen/common/atomic.c > @@ -0,0 +1,35 @@ > +#include <xen/atomic.h> > + > +bool_t atomic_inc_bounded(atomic_t *v, int bound) > +{ > + int old, new, prev = atomic_read(v); > + > + do > + { > + old = prev; > + new = old + 1; > + if ( new >= bound ) > + return 0; > + > + prev = atomic_cmpxchg(v, old, new); > + } while ( prev != old ); > + > + return 1; > +} > + > +bool_t atomic_dec_bounded(atomic_t *v, int bound) > +{ > + int old, new, prev = atomic_read(v); > + > + do > + { > + old = prev; > + new = old - 1; > + if ( new <= bound ) > + return 0; > + > + prev = atomic_cmpxchg(v, old, new); > + } while ( prev != old ); > + > + return 1; > +} Same question here: Do we really need these? There are various uses of cmpxchg() in common code already, and in patch 3 you don't really need the cmpxchg to happen on an atomic_t, so plain cmpxchg() with the little bit of extra logic open coded would seem fine to me. Jan _______________________________________________ Xen-devel mailing list Xen-devel@xxxxxxxxxxxxx http://lists.xen.org/xen-devel
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |