All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Petr Vandrovec" <VANDROVE@vc.cvut.cz>
To: Timur Tabi <ttabi@interactivesi.com>
Cc: linux-kernel@vger.kernel.org, ashok.raj@intel.com
Subject: Re: gnu asm help...
Date: Tue, 19 Jun 2001 01:36:26 MET-1	[thread overview]
Message-ID: <635DA093636@vcnet.vc.cvut.cz> (raw)

On 18 Jun 01 at 18:20, Timur Tabi wrote:
> You want to return the variable?  Try this:
> 
> static __inline__ unsigned long atomic_inc(atomic_t *v)
> {
>     __asm__ __volatile__(
>         LOCK "incl %0"
>         :"=m" (v->counter)
>         :"m" (v->counter));
> 
>     return v->counter;
> }

No. Another CPU might increment value between LOCK INCL and
fetching v->counter. On ia32 architecture you are almost out of
luck. You can either try building atomic_inc around CMPXCHG,
using it as conditional store (but CMPXCHG is not available 
on i386), or you can just guard your atomic variable with 
spinlock - but in that case there is no reason for using atomic_t 
at all. 
                                            Best regards,
                                                Petr Vandrovec
                                                vandrove@vc.cvut.cz
                                                
P.S.: Why you need to know that value? You can either rewrite
your code with atomic_dec_and_test/atomic_inc_and_test, or
you overlooked some race, or you have really strange problem.

             reply	other threads:[~2001-06-18 23:37 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-06-19  1:36 Petr Vandrovec [this message]
2001-06-19 15:48 ` gnu asm help Timur Tabi
2001-06-19 17:21   ` Richard B. Johnson
  -- strict thread matches above, loose matches on Subject: below --
2001-06-19 20:02 Petr Vandrovec
2001-06-19  3:06 Rick Hohensee
2001-06-18 22:56 Raj, Ashok
2001-06-18 23:18 ` Erik Mouw
2001-06-19  6:25   ` Bohdan Vlasyuk
2001-06-18 23:20 ` Timur Tabi
2001-06-19  7:44 ` Alan Cox

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=635DA093636@vcnet.vc.cvut.cz \
    --to=vandrove@vc.cvut.cz \
    --cc=ashok.raj@intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=ttabi@interactivesi.com \
    /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.