> On Thu, Jul 26, 2001 at 03:49:58PM -0700, John Baldwin wrote:
> > > That does set, not test-and-set. What I want is exactly what the Intel
> > > BTS instruction does: atomically test and set a bit.
> > 
> > Unfortunately that is very ia32 specific.  The code would be more
> > friendly on alpha and ia64 at least if the algo was changed to use
> > cmpset on a word instead of test-and-set of a bit.
> 
> Another way to look at it is as an IA-32 specific optimization. For 
> other architectures, we could just use the code you posted earlier.
> 

If I wasn't going to use a non-blocking synchronization loop, this
is how I'd do it.

static __inline int
test_and_set_bit(int nr, volatile void *addr)
{
        char c;

        __asm __volatile("lock ; bts %2, %1 ; setc %0"
            : "=br" (c) : "m" (*(volatile int *)addr), "r" (nr));
        return (c != 0);
}



To Unsubscribe: send mail to [EMAIL PROTECTED]
with "unsubscribe freebsd-hackers" in the body of the message

Reply via email to