On Wed, Mar 22, 2006 at 07:10:28PM +0100, Michael Schulte wrote:
> You should find out the "atomic" native assembler instruction
> on your system that does a "cas" and try to use this for your purpose.
> Otherwise you will always have races in your code.
Well, the code below does, in fact, use an atomic operation:
> > asm("lock bts $0,(%edx)");
the algorithm is essentially:
if (atomic_set(arg4, 0, 1) fails)
return (0);
if (*arg1 != arg2) {
*arg4 = 0;
return (0);
*arg1 = arg3
*arg4 = 0;
return (1);
which might work, but is really inefficient. They should use either
atomic_cas(3C) (S10 update 1 and later), or use the CMPXCHG instruction.
Cheers,
- jonathan
> > asm(" jc label2");
> > //moving of first and second pararmeters into the registers
> > asm(" movl 8(%ebp),%ebx");
> > asm(" movl 12(%ebp),%ecx"); //after performing CAS operation
> > // Comparing if (*p) == i
> > asm(" cmp %ecx,(%ebx)");
> > asm(" je label1");
> > asm(" movl $0,%eax");
> > asm(" movl $0,(%edx)");
> > asm(" leave");
> > asm(" ret ");
> > // set (*p) = j and set the temp variable to 0 so that another
> > // may perform the operation
> > asm("label1: ");
> > asm(" movl 16(%ebp),%ecx");
> > asm(" movl %ecx ,(%ebx)");
> > asm(" movl $0,(%edx)");
> > // we are setting the return value in the register %eax
> > asm(" movl $1,%eax");
> > asm(" leave");
> > asm(" ret");
> > asm("label2: ");
> > asm(" movl $0,%eax");
> > asm(" leave");
> > asm(" ret");
> >
> >}//end of cas
> >
> >
> >Rama
> >This message posted from opensolaris.org
> >_______________________________________________
> >perf-discuss mailing list
> >[email protected]
>
>
> --
> Michael Schulte
> [EMAIL PROTECTED]
> OpenSolaris Kernel Development http://opensolaris.org/
> _______________________________________________
> perf-discuss mailing list
> [email protected]
--
Jonathan Adams, Solaris Kernel Development
_______________________________________________
perf-discuss mailing list
[email protected]