smpprim.h 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. /*
  2. * smpprim.h: SMP locking primitives on the Sparc
  3. *
  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.
  6. *
  7. * Copyright (C) 1995 David S. Miller (davem@caip.rutgers.edu)
  8. */
  9. #ifndef __SPARC_SMPPRIM_H
  10. #define __SPARC_SMPPRIM_H
  11. /* Test and set the unsigned byte at ADDR to 1. Returns the previous
  12. * value. On the Sparc we use the ldstub instruction since it is
  13. * atomic.
  14. */
  15. static inline __volatile__ char test_and_set(void *addr)
  16. {
  17. char state = 0;
  18. __asm__ __volatile__("ldstub [%0], %1 ! test_and_set\n\t"
  19. "=r" (addr), "=r" (state) :
  20. "0" (addr), "1" (state) : "memory");
  21. return state;
  22. }
  23. /* Initialize a spin-lock. */
  24. static inline __volatile__ smp_initlock(void *spinlock)
  25. {
  26. /* Unset the lock. */
  27. *((unsigned char *) spinlock) = 0;
  28. return;
  29. }
  30. /* This routine spins until it acquires the lock at ADDR. */
  31. static inline __volatile__ smp_lock(void *addr)
  32. {
  33. while(test_and_set(addr) == 0xff)
  34. ;
  35. /* We now have the lock */
  36. return;
  37. }
  38. /* This routine releases the lock at ADDR. */
  39. static inline __volatile__ smp_unlock(void *addr)
  40. {
  41. *((unsigned char *) addr) = 0;
  42. }
  43. #endif /* !(__SPARC_SMPPRIM_H) */