root/include/asm-sparc/smpprim.h

/* [previous][next][first][last][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. test_and_set
  2. smp_initlock
  3. smp_lock
  4. smp_unlock

   1 /*  smpprim.h:  SMP locking primitives on the Sparc
   2  *
   3  *  God knows we won't be actually using this code for some time
   4  *  but I thought I'd write it since I knew how.
   5  *
   6  *  Copyright (C) 1995 David S. Miller (davem@caip.rutgers.edu)
   7  */
   8 
   9 #ifndef __SPARC_SMPPRIM_H
  10 #define __SPARC_SMPPRIM_H
  11 
  12 /* Test and set the unsigned byte at ADDR to 1.  Returns the previous
  13  * value.  On the Sparc we use the ldstub instruction since it is
  14  * atomic.
  15  */
  16 
  17 extern inline volatile char test_and_set(void *addr)
     /* [previous][next][first][last][top][bottom][index][help] */
  18 {
  19         char state = 0;
  20 
  21         __asm__ __volatile__("ldstub [%0], %1         ! test_and_set\n\t"
  22                              "=r" (addr), "=r" (state) :
  23                              "0" (addr), "1" (state) : "memory");
  24 
  25         return state;
  26 }
  27 
  28 /* Initialize a spin-lock. */
  29 extern inline volatile smp_initlock(void *spinlock)
     /* [previous][next][first][last][top][bottom][index][help] */
  30 {
  31         /* Unset the lock. */
  32         *((unsigned char *) spinlock) = 0;
  33 
  34         return;
  35 }
  36 
  37 /* This routine spins until it acquires the lock at ADDR. */
  38 extern inline volatile smp_lock(void *addr)
     /* [previous][next][first][last][top][bottom][index][help] */
  39 {
  40         while(test_and_set(addr) == 0xff)
  41                 ;
  42 
  43         /* We now have the lock */
  44         return;
  45 }
  46 
  47 /* This routine releases the lock at ADDR. */
  48 extern inline volatile smp_unlock(void *addr)
     /* [previous][next][first][last][top][bottom][index][help] */
  49 {
  50         *((unsigned char *) addr) = 0;
  51 }
  52 
  53 #endif /* !(__SPARC_SMPPRIM_H) */

/* [previous][next][first][last][top][bottom][index][help] */