[Qemu-devel] [RFC 1/6] bitmap: add atomic set functions

2014-11-27 Thread Stefan Hajnoczi
Use atomic_or() for atomic bitmaps where several threads may set bits at the same time. This avoids the race condition between threads loading an element, bitwise ORing, and then storing the element. Most bitmap users don't need atomicity so introduce new functions. Signed-off-by: Stefan Hajnocz

Re: [Qemu-devel] [RFC 1/6] bitmap: add atomic set functions

2014-11-27 Thread Paolo Bonzini
On 27/11/2014 13:29, Stefan Hajnoczi wrote: > +void bitmap_set_atomic(unsigned long *map, long start, long nr) > +{ > +unsigned long *p = map + BIT_WORD(start); > +const long size = start + nr; > +int bits_to_set = BITS_PER_LONG - (start % BITS_PER_LONG); > +unsigned long mask_to_

Re: [Qemu-devel] [RFC 1/6] bitmap: add atomic set functions

2014-12-01 Thread Stefan Hajnoczi
On Thu, Nov 27, 2014 at 05:42:41PM +0100, Paolo Bonzini wrote: > > > On 27/11/2014 13:29, Stefan Hajnoczi wrote: > > +void bitmap_set_atomic(unsigned long *map, long start, long nr) > > +{ > > +unsigned long *p = map + BIT_WORD(start); > > +const long size = start + nr; > > +int bits_