From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42799) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YWLAD-0004tf-D5 for qemu-devel@nongnu.org; Fri, 13 Mar 2015 04:41:50 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YWLAA-0001jX-NO for qemu-devel@nongnu.org; Fri, 13 Mar 2015 04:41:49 -0400 Received: from mail-wi0-x234.google.com ([2a00:1450:400c:c05::234]:33377) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YWLAA-0001jR-F8 for qemu-devel@nongnu.org; Fri, 13 Mar 2015 04:41:46 -0400 Received: by widfb4 with SMTP id fb4so10181907wid.0 for ; Fri, 13 Mar 2015 01:41:45 -0700 (PDT) Sender: Paolo Bonzini Message-ID: <5502A2C6.6010501@redhat.com> Date: Fri, 13 Mar 2015 09:41:42 +0100 From: Paolo Bonzini MIME-Version: 1.0 References: <1426210723-16735-1-git-send-email-famz@redhat.com> <1426210723-16735-2-git-send-email-famz@redhat.com> <55029B3E.4000501@redhat.com> <20150313081603.GB18156@ad.nay.redhat.com> <5502A086.5030208@redhat.com> In-Reply-To: <5502A086.5030208@redhat.com> Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH v2 1/4] exec: Atomic access to bounce buffer List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Fam Zheng Cc: qemu-devel@nongnu.org On 13/03/2015 09:32, Paolo Bonzini wrote: > > > On 13/03/2015 09:16, Fam Zheng wrote: >>>>>> + if (atomic_cmpxchg(&bounce.in_use, false, true)) { >>>> >>>> atomic_or is enough... >> atomic_cmpxchg is here to take the ownership of bounce iff it is not in use, so >> I think it is necessary. > > It's changing false to true and true to true, so you can do > > if (atomic_or(&bounce.in_use, 1)) { > // was true already > } ... and actually, atomic_xchg is even better (on x86, atomic_or is compiled into a cmpxchg loop, but atomic_xchg is a single instruction). Paolo