lkml.org 
[lkml]   [2001]   [Jun]   [18]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
From
Date
SubjectRe: gnu asm help...
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.
-
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/

\
 
 \ /
  Last update: 2005-03-22 12:55    [W:0.026 / U:4.948 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site