new timeout structure (linked lists)
authorBill Joy <wnj@ucbvax.Berkeley.EDU>
Sat, 18 Apr 1981 08:52:57 +0000 (00:52 -0800)
committerBill Joy <wnj@ucbvax.Berkeley.EDU>
Sat, 18 Apr 1981 08:52:57 +0000 (00:52 -0800)
SCCS-vsn: sys/kern/kern_clock.c 4.20
SCCS-vsn: sys/vax/vax/machdep.c 4.32

usr/src/sys/kern/kern_clock.c
usr/src/sys/vax/vax/machdep.c

index b38927c..46b5202 100644 (file)
@@ -1,4 +1,4 @@
-/*     kern_clock.c    4.19    81/04/13        */
+/*     kern_clock.c    4.20    81/04/17        */
 
 #include "../h/param.h"
 #include "../h/systm.h"
 
 #include "../h/param.h"
 #include "../h/systm.h"
@@ -62,12 +62,10 @@ hardclock(pc, ps)
        /*
         * update callout times
         */
        /*
         * update callout times
         */
-       if (callout[0].c_func == NULL)
-               goto out;
-       p1 = &callout[0];
-       while (p1->c_time<=0 && p1->c_func!=NULL)
-               p1++;
-       p1->c_time--;
+       for (p1 = calltodo.c_next; p1 && p1->c_time <= 0; p1 = p1->c_next)
+               ;
+       if (p1)
+               p1->c_time--;
 out:
 
        /*
 out:
 
        /*
@@ -169,22 +167,24 @@ softclock(pc, ps)
        register struct callout *p1, *p2;
        register struct proc *pp;
        register int a, s;
        register struct callout *p1, *p2;
        register struct proc *pp;
        register int a, s;
+       caddr_t arg;
+       int (*func)();
 
        /*
         * Perform callouts (but not after panic's!)
         */
 
        /*
         * Perform callouts (but not after panic's!)
         */
-       if (panicstr == 0 && callout[0].c_time <= 0) {
-               p1 = &callout[0];
-               while (p1->c_func != 0 && p1->c_time <= 0) {
-                       (*p1->c_func)(p1->c_arg);
-                       p1++;
-               }
-               p2 = &callout[0];
-               while (p2->c_func = p1->c_func) {
-                       p2->c_time = p1->c_time;
-                       p2->c_arg = p1->c_arg;
-                       p1++;
-                       p2++;
+       if (panicstr == 0) {
+               for (;;) {
+                       s = spl7();
+                       if ((p1 = calltodo.c_next) == 0 || p1->c_time > 0)
+                               break;
+                       calltodo.c_next = p1->c_next;
+                       arg = p1->c_arg;
+                       func = p1->c_func;
+                       p1->c_next = callfree;
+                       callfree = p1;
+                       (void) splx(s);
+                       (*func)(arg);
                }
        }
 
                }
        }
 
@@ -400,7 +400,7 @@ softclock(pc, ps)
 /*
  * Timeout is called to arrange that
  * fun(arg) is called in tim/hz seconds.
 /*
  * Timeout is called to arrange that
  * fun(arg) is called in tim/hz seconds.
- * An entry is sorted into the callout
+ * An entry is linked into the callout
  * structure.  The time in each structure
  * entry is the number of hz's more
  * than the previous entry.
  * structure.  The time in each structure
  * entry is the number of hz's more
  * than the previous entry.
@@ -415,7 +415,7 @@ timeout(fun, arg, tim)
        int (*fun)();
        caddr_t arg;
 {
        int (*fun)();
        caddr_t arg;
 {
-       register struct callout *p1, *p2, *p3;
+       register struct callout *p1, *p2, *pnew;
        register int t;
        int s;
 
        register int t;
        int s;
 
@@ -426,28 +426,19 @@ timeout(fun, arg, tim)
                panic("timeout ttrstr arg");
 /* END DEBUGGING CODE */
        t = tim;
                panic("timeout ttrstr arg");
 /* END DEBUGGING CODE */
        t = tim;
-       p1 = &callout[0];
        s = spl7();
        s = spl7();
-       while (p1->c_func != 0 && p1->c_time <= t) {
-               t -= p1->c_time;
-               p1++;
-       }
-       p1->c_time -= t;
-       p2 = p1;
-       p3 = callout+(ncallout-2);
-       while (p2->c_func != 0) {
-               if (p2 >= p3)
-                       panic("timeout table overflow");
-               p2++;
-       }
-       while (p2 >= p1) {
-               (p2+1)->c_time = p2->c_time;
-               (p2+1)->c_func = p2->c_func;
-               (p2+1)->c_arg = p2->c_arg;
-               p2--;
-       }
-       p1->c_time = t;
-       p1->c_func = fun;
-       p1->c_arg = arg;
+       pnew = callfree;
+       if (pnew == NULL)
+               panic("timeout table overflow");
+       callfree = pnew->c_next;
+       pnew->c_arg = arg;
+       pnew->c_func = fun;
+       for (p1 = &calltodo; (p2 = p1->c_next) && p2->c_time < t; p1 = p2)
+               t -= p2->c_time;
+       p1->c_next = pnew;
+       pnew->c_next = p2;
+       pnew->c_time = t;
+       if (p2)
+               p2->c_time -= t;
        splx(s);
 }
        splx(s);
 }
index 92019e3..3ba16ed 100644 (file)
@@ -1,4 +1,4 @@
-/*     machdep.c       4.31    81/04/13        */
+/*     machdep.c       4.32    81/04/17        */
 
 #include "../h/param.h"
 #include "../h/systm.h"
 
 #include "../h/param.h"
 #include "../h/systm.h"
@@ -136,6 +136,13 @@ startup(firstaddr)
        }
        mtpr(TBIA, 1);
 
        }
        mtpr(TBIA, 1);
 
+       /*
+        * Initialize callouts
+        */
+       callfree = callout;
+       for (i = 1; i < ncallout; i++)
+               callout[i-1].c_next = &callout[i];
+
        /*
         * Initialize memory allocator and swap
         * and user page table maps.
        /*
         * Initialize memory allocator and swap
         * and user page table maps.