All of lore.kernel.org
 help / color / mirror / Atom feed
From: Brian Gerst <bgerst@didntduck.org>
To: Gregory Giguashvili <Gregoryg@ParadigmGeo.com>
Cc: "Linux Kernel (E-mail)" <linux-kernel@vger.kernel.org>
Subject: Re: Atomic operations
Date: Mon, 03 Jun 2002 14:39:23 -0400	[thread overview]
Message-ID: <3CFBB7DB.831BE453@didntduck.org> (raw)
In-Reply-To: <EE83E551E08D1D43AD52D50B9F5110927E7A10@ntserver2>

Gregory Giguashvili wrote:
> 
> Hello,
> 
> I wonder if someone can help me to change the behaviour of the atomic
> functions available in <asm/atomic.h> 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

  parent reply	other threads:[~2002-06-03 18:39 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-06-03 15:04 Atomic operations Gregory Giguashvili
2002-06-03 17:27 ` H. Peter Anvin
2002-06-03 18:08 ` Richard B. Johnson
2002-06-03 19:36   ` Thunder from the hill
2002-06-03 21:30     ` Richard B. Johnson
2002-06-03 18:39 ` Brian Gerst [this message]
2002-06-03 19:49   ` H. Peter Anvin
  -- strict thread matches above, loose matches on Subject: below --
2002-06-03 15:58 Gregory Giguashvili
2002-06-03 19:09 Gregory Giguashvili
2002-06-03 18:43 ` H. Peter Anvin
2002-06-04  9:23 Gregory Giguashvili
2009-03-26  0:17 Timothy Hayes
2009-03-26  7:25 ` Keir Fraser
2009-03-26  7:34   ` Juergen Gross
2009-03-26  7:50     ` Keir Fraser
2009-03-27 17:22       ` Timothy Hayes
2009-03-27 17:56         ` Keir Fraser
2009-03-27 20:00           ` Timothy Hayes
2013-02-24  9:42 atomic operations Shraddha Kamat
2013-02-24 10:50 ` richard -rw- weinberger
2013-02-24 23:24   ` Valdis.Kletnieks at vt.edu
2013-02-24 12:50 ` Peter Teoh
2013-02-24 12:53   ` Peter Teoh
2013-02-25  7:15     ` Kumar amit mehta
2013-03-01  5:44   ` Arun KS

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=3CFBB7DB.831BE453@didntduck.org \
    --to=bgerst@didntduck.org \
    --cc=Gregoryg@ParadigmGeo.com \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.