1 /* $Id: smpprim.h,v 1.5 1996/08/29 09:48:49 davem Exp $
2 * smpprim.h: SMP locking primitives on the Sparc
4 * God knows we won't be actually using this code for some time
5 * but I thought I'd write it since I knew how.
7 * Copyright (C) 1995 David S. Miller (davem@caip.rutgers.edu)
10 #ifndef __SPARC_SMPPRIM_H
11 #define __SPARC_SMPPRIM_H
13 /* Test and set the unsigned byte at ADDR to 1. Returns the previous
14 * value. On the Sparc we use the ldstub instruction since it is
18 extern __inline__ __volatile__ char test_and_set(void *addr)
22 __asm__ __volatile__("ldstub [%0], %1 ! test_and_set\n\t"
23 "=r" (addr), "=r" (state) :
24 "0" (addr), "1" (state) : "memory");
29 /* Initialize a spin-lock. */
30 extern __inline__ __volatile__ smp_initlock(void *spinlock)
33 *((unsigned char *) spinlock) = 0;
38 /* This routine spins until it acquires the lock at ADDR. */
39 extern __inline__ __volatile__ smp_lock(void *addr)
41 while(test_and_set(addr) == 0xff)
44 /* We now have the lock */
48 /* This routine releases the lock at ADDR. */
49 extern __inline__ __volatile__ smp_unlock(void *addr)
51 *((unsigned char *) addr) = 0;
54 #endif /* !(__SPARC_SMPPRIM_H) */