root/include/asm-i386/smp_lock.h

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

INCLUDED FROM


DEFINITIONS

This source file includes following definitions.
  1. lock_kernel
  2. unlock_kernel

   1 #ifndef __LINUX_SMPLOCK_H
   2 #define __LINUX_SMPLOCK_H
   3 
   4 #ifdef __SMP__
   5 
   6 /*
   7  *      Locking the kernel 
   8  */
   9  
  10 extern __inline void lock_kernel(void)
     /* [previous][next][first][last][top][bottom][index][help] */
  11 {
  12         unsigned long flags;
  13         int proc = smp_processor_id();
  14 
  15         save_flags(flags);
  16         cli();
  17         /* set_bit works atomic in SMP machines */
  18         while(set_bit(0, (void *)&kernel_flag)) 
  19         {
  20                 /*
  21                  *      We just start another level if we have the lock 
  22                  */
  23                 if (proc == active_kernel_processor)
  24                         break;
  25                 do 
  26                 {
  27                         smp_spins++;
  28                         /*
  29                          *      Doing test_bit here doesn't lock the bus 
  30                          */
  31                         if (test_bit(proc, (void *)&smp_invalidate_needed))
  32                                 if (clear_bit(proc, (void *)&smp_invalidate_needed))
  33                                         local_invalidate();
  34                 }
  35                 while(test_bit(0, (void *)&kernel_flag));
  36         }
  37         /* 
  38          *      We got the lock, so tell the world we are here and increment
  39          *      the level counter 
  40          */
  41         active_kernel_processor = proc;
  42         kernel_counter++;
  43         restore_flags(flags);
  44 }
  45 
  46 extern __inline void unlock_kernel(void)
     /* [previous][next][first][last][top][bottom][index][help] */
  47 {
  48         unsigned long flags;
  49         save_flags(flags);
  50         cli();
  51         /*
  52          *      If it's the last level we have in the kernel, then
  53          *      free the lock 
  54          */
  55         if (kernel_counter == 0)
  56                 panic("Kernel counter wrong.\n"); /* FIXME: Why is kernel_counter sometimes 0 here? */
  57         
  58         if(! --kernel_counter) 
  59         {
  60                 active_kernel_processor = NO_PROC_ID;
  61                 clear_bit(0, (void *)&kernel_flag);
  62         }
  63         restore_flags(flags);
  64 }
  65 
  66 #endif
  67 #endif

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