The Design and Implementation of the FreeBSD Operating System, Second Edition
Now available: The Design and Implementation of the FreeBSD Operating System (Second Edition)


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]

FreeBSD/Linux Kernel Cross Reference
sys/port/alarm.c

Version: -  FREEBSD  -  FREEBSD-13-STABLE  -  FREEBSD-13-0  -  FREEBSD-12-STABLE  -  FREEBSD-12-0  -  FREEBSD-11-STABLE  -  FREEBSD-11-0  -  FREEBSD-10-STABLE  -  FREEBSD-10-0  -  FREEBSD-9-STABLE  -  FREEBSD-9-0  -  FREEBSD-8-STABLE  -  FREEBSD-8-0  -  FREEBSD-7-STABLE  -  FREEBSD-7-0  -  FREEBSD-6-STABLE  -  FREEBSD-6-0  -  FREEBSD-5-STABLE  -  FREEBSD-5-0  -  FREEBSD-4-STABLE  -  FREEBSD-3-STABLE  -  FREEBSD22  -  l41  -  OPENBSD  -  linux-2.6  -  MK84  -  PLAN9  -  xnu-8792 
SearchContext: -  none  -  3  -  10 

    1 #include        "u.h"
    2 #include        "../port/lib.h"
    3 #include        "mem.h"
    4 #include        "dat.h"
    5 #include        "fns.h"
    6 
    7 static Alarms   alarms;
    8 static Rendez   alarmr;
    9 
   10 void
   11 alarmkproc(void*)
   12 {
   13         Proc *rp;
   14         ulong now;
   15 
   16         for(;;){
   17                 now = MACHP(0)->ticks;
   18                 qlock(&alarms);
   19                 while((rp = alarms.head) && rp->alarm <= now){
   20                         if(rp->alarm != 0L){
   21                                 if(canqlock(&rp->debug)){
   22                                         if(!waserror()){
   23                                                 postnote(rp, 0, "alarm", NUser);
   24                                                 poperror();
   25                                         }
   26                                         qunlock(&rp->debug);
   27                                         rp->alarm = 0L;
   28                                 }else
   29                                         break;
   30                         }
   31                         alarms.head = rp->palarm;
   32                 }
   33                 qunlock(&alarms);
   34 
   35                 sleep(&alarmr, return0, 0);
   36         }
   37 }
   38 
   39 /*
   40  *  called every clock tick
   41  */
   42 void
   43 checkalarms(void)
   44 {
   45         Proc *p;
   46         ulong now;
   47 
   48         p = alarms.head;
   49         now = MACHP(0)->ticks;
   50 
   51         if(p && p->alarm <= now)
   52                 wakeup(&alarmr);
   53 }
   54 
   55 ulong
   56 procalarm(ulong time)
   57 {
   58         Proc **l, *f;
   59         ulong when, old;
   60 
   61         if(up->alarm)
   62                 old = tk2ms(up->alarm - MACHP(0)->ticks);
   63         else
   64                 old = 0;
   65         if(time == 0) {
   66                 up->alarm = 0;
   67                 return old;
   68         }
   69         when = ms2tk(time)+MACHP(0)->ticks;
   70 
   71         qlock(&alarms);
   72         l = &alarms.head;
   73         for(f = *l; f; f = f->palarm) {
   74                 if(up == f){
   75                         *l = f->palarm;
   76                         break;
   77                 }
   78                 l = &f->palarm;
   79         }
   80 
   81         up->palarm = 0;
   82         if(alarms.head) {
   83                 l = &alarms.head;
   84                 for(f = *l; f; f = f->palarm) {
   85                         if(f->alarm > when) {
   86                                 up->palarm = f;
   87                                 *l = up;
   88                                 goto done;
   89                         }
   90                         l = &f->palarm;
   91                 }
   92                 *l = up;
   93         }
   94         else
   95                 alarms.head = up;
   96 done:
   97         up->alarm = when;
   98         qunlock(&alarms);
   99 
  100         return old;
  101 }

Cache object: 07d7afdc1391bd881448a62c70b59808


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]


This page is part of the FreeBSD/Linux Linux Kernel Cross-Reference, and was automatically generated using a modified version of the LXR engine.