Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S935050AbdCXSFN (ORCPT ); Fri, 24 Mar 2017 14:05:13 -0400 Received: from merlin.infradead.org ([205.233.59.134]:32940 "EHLO merlin.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S934492AbdCXSEy (ORCPT ); Fri, 24 Mar 2017 14:04:54 -0400 Date: Fri, 24 Mar 2017 19:04:41 +0100 From: Peter Zijlstra To: Andy Lutomirski Cc: Dmitry Vyukov , Andrew Morton , Andy Lutomirski , Borislav Petkov , Brian Gerst , Denys Vlasenko , "H. Peter Anvin" , Josh Poimboeuf , Linus Torvalds , Paul McKenney , Thomas Gleixner , Ingo Molnar , LKML Subject: Re: locking/atomic: Introduce atomic_try_cmpxchg() Message-ID: <20170324180441.gj5uhlttdzt7zxod@hirez.programming.kicks-ass.net> References: <20170324142140.vpyzl755oj6rb5qv@hirez.programming.kicks-ass.net> <20170324164108.ibcxxqbhvx6ao54r@hirez.programming.kicks-ass.net> <20170324172342.radlrhk2z6mwmdgk@hirez.programming.kicks-ass.net> <20170324180025.tumlczzf4ji3uzpo@hirez.programming.kicks-ass.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20170324180025.tumlczzf4ji3uzpo@hirez.programming.kicks-ass.net> User-Agent: NeoMutt/20170113 (1.7.2) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 675 Lines: 22 On Fri, Mar 24, 2017 at 07:00:25PM +0100, Peter Zijlstra wrote: > static inline bool try_cmpxchg2(unsigned int *ptr, unsigned int *val, unsigned int new) > { > unsigned int old = *val; > bool success; > > asm volatile goto("lock cmpxchgl %[new], %[ptr]; " > "jnz %[label]" > : /* no output */ > : [ptr] "+m" (*ptr), > [old] "+a" (old) > [new] "r" (new) > : "memory" > : label); > return 1; > > label: > *val = old; > return 0; > } N/m, I'm apparently so tired I didn't see the compiler errors :/