Kernel: Merge 16-bit and 32-bit tick counters into one structure
authorWill Sowerbutts <will@sowerbutts.com>
Sat, 27 Dec 2014 16:32:15 +0000 (16:32 +0000)
committerWill Sowerbutts <will@sowerbutts.com>
Sat, 27 Dec 2014 16:38:40 +0000 (16:38 +0000)
Kernel/include/kdata.h
Kernel/kdata.c
Kernel/process.c
Kernel/syscall_proc.c
Kernel/timer.c

index 7694aa9..1d74467 100644 (file)
@@ -32,8 +32,12 @@ extern uint8_t ticks_this_dsecond;       /* Tick counter for counting off one de
 extern uint16_t runticks;  /* Number of ticks current process has been swapped in */
 
 extern time_t tod;      /* Time of day */
-extern clock_t ticks;      /* 32-bit count of ticks since boot */
-extern uint16_t miniticks; /* 16-bit count of ticks since boot */
+
+typedef union {            /* this structure is endian dependent */
+    clock_t  full;         /* 32-bit count of ticks since boot */
+    uint16_t mini;         /* 16-bit count of ticks since boot */
+} ticks_t;
+extern ticks_t ticks;
 
 extern uint8_t *swapbase;  /* Used by device driver for swapping */
 extern unsigned swapcnt;
index 95a4063..5b5ae50 100644 (file)
@@ -13,8 +13,7 @@ uint8_t ticks_this_dsecond;
 inoptr root;
 uint16_t waitno;
 time_t tod;                    // time of day
-clock_t ticks;                 // 32-bit system tick counter
-uint16_t miniticks;     // 16-bit system tick counter
+ticks_t ticks;
 
 int16_t acct_fh = -1;          /* Accounting file handle */
 
index e47d468..0b87669 100644 (file)
@@ -327,8 +327,8 @@ void timer_interrupt(void)
                else
                        udata.u_utime++;
        }
-       ticks++;
-       miniticks++;
+
+       ticks.full++;
 
        /* Do once-per-decisecond things - this doesn't work out well on
           boxes with 64 ticks/second.. need a better approach */
index 342ea7c..4ec5d68 100644 (file)
@@ -144,7 +144,7 @@ int16_t _time(void)
                        uput(&t, tvec, sizeof(t));
                        return (0);
                case 1:
-                       uput(&t.low, &ticks, sizeof(ticks));
+                       uput(&t.low, &ticks.full, sizeof(ticks));
                        uzero(&t.high, sizeof(t.high));
                        return 0;
                default:
index 9f50e03..f80708c 100644 (file)
@@ -12,14 +12,14 @@ timer_t set_timer_duration(uint16_t duration)
        }
     /* obvious code is return (miniticks+duration), however we have to do */
     /* it this longwinded way or sdcc doesn't load miniticks atomically */
-    a = miniticks;
+    a = ticks.mini;
     a += duration;
     return a;
 }
 
 bool timer_expired(timer_t timer_val)
 {
-       return ((timer_val - miniticks) & 0x8000);
+       return ((timer_val - ticks.mini) & 0x8000);
 }
 
 /*-----------------------------------------------------------*/