Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S265065AbTFLXbu (ORCPT ); Thu, 12 Jun 2003 19:31:50 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S265068AbTFLXbt (ORCPT ); Thu, 12 Jun 2003 19:31:49 -0400 Received: from dp.samba.org ([66.70.73.150]:39627 "EHLO lists.samba.org") by vger.kernel.org with ESMTP id S265065AbTFLXbs (ORCPT ); Thu, 12 Jun 2003 19:31:48 -0400 From: Paul Mackerras MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Message-ID: <16105.3943.510055.309447@nanango.paulus.ozlabs.org> Date: Fri, 13 Jun 2003 09:40:23 +1000 (EST) To: Patrick Mochel Cc: Robert Love , Greg KH , Andrew Morton , , Subject: Re: [PATCH] udev enhancements to use kernel event queue In-Reply-To: References: <1055460564.662.339.camel@localhost> X-Mailer: VM 6.75 under Emacs 20.7.2 Sender: linux-kernel-owner@vger.kernel.org X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1118 Lines: 36 Patrick Mochel writes: > It seems like the following should work. Would someone mind commenting on > it? > +/** > + * atomic_inc_and_read - increment atomic variable and return new value > + * @v: pointer of type atomic_t > + * > + * Atomically increments @v by 1. Note that the guaranteed > + * useful range of an atomic_t is only 24 bits. > + */ > +static inline int atomic_inc_and_read(atomic_t *v) > +{ > + __asm__ __volatile__( > + LOCK "incl %0" > + :"=m" (v->counter) > + :"m" (v->counter)); > + return v->counter; > +} BZZZT. If another CPU is also doing atomic_inc_and_read you could end up with both calls returning the same value. You can't do atomic_inc_and_read on 386. You can on cpus that have cmpxchg (e.g. later x86). You can also on machines with load-locked and store-conditional instructions (alpha, ppc, probably most other RISCs). Paul. - To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/