Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id ; Mon, 3 Jun 2002 14:39:35 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id ; Mon, 3 Jun 2002 14:39:35 -0400 Received: from quark.didntduck.org ([216.43.55.190]:51474 "EHLO quark.didntduck.org") by vger.kernel.org with ESMTP id ; Mon, 3 Jun 2002 14:39:33 -0400 Message-ID: <3CFBB7DB.831BE453@didntduck.org> Date: Mon, 03 Jun 2002 14:39:23 -0400 From: Brian Gerst X-Mailer: Mozilla 4.76 [en] (WinNT; U) X-Accept-Language: en MIME-Version: 1.0 To: Gregory Giguashvili CC: "Linux Kernel (E-mail)" Subject: Re: Atomic operations In-Reply-To: Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org X-Mailing-List: linux-kernel@vger.kernel.org Gregory Giguashvili wrote: > > Hello, > > I wonder if someone can help me to change the behaviour of the atomic > functions available in include file. The operations I need to > implement are described below: > > atomic_t test_and_set (int i, atomic_t* v) > { > atomic_t old = *v; > v->counter = i; > return old; > } What you have coded is really an exchange, not a test. Here is the asm equivalent of what you coded: int atomic_xchg(int i, atomic_t *v) { int ret; __asm__("xchgl %1,%0" : "=m" (v->counter), "=r" (ret) : "0" (v->counter), "1" (i)); return ret; } > > atomic_t test_then_add (int i, atomic_t* v) > { > atomic_t old = *v; > v->counter += i; > return old; > } int atomic_xadd(int i, atomic_t *v) { int ret; __asm__(LOCK "xaddl %1,%0" : "=m" (v->counter), "=r" (ret) : "0" (v->counter), "1" (i)); return ret; } This one only works on 486+, but there are practically no real 386 SMP systems. -- Brian Gerst - 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/