Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 03 Dec 1996 00:54:40 -0600
From:      Chris Csanady <ccsanady@friley216.res.iastate.edu>
To:        freebsd-smp@freebsd.org
Subject:   spin locks...
Message-ID:  <199612030654.AAA12221@friley216.res.iastate.edu>

next in thread | raw e-mail | index | archive | help
Its something we could use, so I thought I'd give it a shot.  I thought it
would make a nice first assembly project, right?  Yeah.. sure.  I have never
been so frustrated with something so obviously simple.

When I try to link it into a test program, it segfaults.  The only way I
could obtain predictable behavior was to take out the cmpxchg and lock.

Could someone please point out my error here?

.text
        .align  2,0x90
.globl _get_spinlock
_get_spinlock:
        pushl   %eax
        pushl   %ecx
        pushl   %edx
        movl    _smp_active, %eax
        cmpl    $0, %eax
        jne     1f
        jmp     4
1:      movl    4(%esp), %edx
        movl    $1, %ecx
2:      lock
        cmpxchg %ecx, (%edx)
        je      3f
        jmp     4
3:      cmpl    %ecx, (%edx)
        je      3b
        jmp     2b
4:      popl    %edx
        popl    %ecx
        popl    %eax
        ret

--Chris Csanady






Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199612030654.AAA12221>