1 // Mutual exclusion lock for short code fragments 2 struct spinlock { 3 uint locked; // Is the lock held? 4 5 // For debugging: 6 char *name; // Name of lock. 7 struct cpu *cpu; // The cpu holding the lock. 8 uint pcs[10]; // The call stack (an array of program counters) 9 // that locked the lock. 10 }; 11 12 // Lock that maybe held across sleeps 13 struct sleeplock { 14 uint locked; // Is the lock held? 15 }; 16 17