root/sleeplock.c

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

DEFINITIONS

This source file includes following definitions.
  1. initsleeplock
  2. acquiresleep
  3. releasesleep
  4. holdingsleep

   1 // Sleeping locks
   2 
   3 #include "types.h"
   4 #include "defs.h"
   5 #include "param.h"
   6 #include "x86.h"
   7 #include "memlayout.h"
   8 #include "mmu.h"
   9 #include "proc.h"
  10 #include "spinlock.h"
  11 #include "sleeplock.h"
  12 
  13 void
  14 initsleeplock(struct sleeplock *lk, char *name)
     /* [previous][next][first][last][top][bottom][index][help]  */
  15 {
  16   initlock(&lk->lk, "sleep lock");
  17   lk->name = name;
  18   lk->locked = 0;
  19   lk->pid = 0;
  20 }
  21 
  22 void
  23 acquiresleep(struct sleeplock *lk)
     /* [previous][next][first][last][top][bottom][index][help]  */
  24 {
  25   acquire(&lk->lk);
  26   while (lk->locked) {
  27     sleep(lk, &lk->lk);
  28   }
  29   lk->locked = 1;
  30   lk->pid = myproc()->pid;
  31   release(&lk->lk);
  32 }
  33 
  34 void
  35 releasesleep(struct sleeplock *lk)
     /* [previous][next][first][last][top][bottom][index][help]  */
  36 {
  37   acquire(&lk->lk);
  38   lk->locked = 0;
  39   lk->pid = 0;
  40   wakeup(lk);
  41   release(&lk->lk);
  42 }
  43 
  44 int
  45 holdingsleep(struct sleeplock *lk)
     /* [previous][next][first][last][top][bottom][index][help]  */
  46 {
  47   int r;
  48   
  49   acquire(&lk->lk);
  50   r = lk->locked && (lk->pid == myproc()->pid);
  51   release(&lk->lk);
  52   return r;
  53 }
  54 
  55 
  56 

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