ref: d1b96d17b26c6284b605ccc65abe91357559d53c
parent: 420c7545c8260954be15e83a26595e2e0bd00f1c
author: cinap_lenrek <cinap_lenrek@felloff.net>
date: Sat Aug 16 17:04:41 EDT 2014
kernel: fix todfix() race we have to recheck the condition under tod lock, otherwise another process can come in and updated tod.last and tod.off and once we have the lock, we would make time jump backwards.
--- a/sys/src/9/port/tod.c
+++ b/sys/src/9/port/tod.c
@@ -198,11 +198,13 @@
uvlong x;
ticks = fastticks(nil);
+ diff = ticks - tod.last;
+ if(diff <= tod.hz)
+ return;
+ ilock(&tod);
diff = ticks - tod.last;
if(diff > tod.hz){- ilock(&tod);
-
/* convert to epoch */
mul64fract(&x, diff, tod.multiplier);
if(x > 30000000000ULL) iprint("todfix %llud\n", x);@@ -211,9 +213,8 @@
/* protect against overflows */
tod.last = ticks;
tod.off = x;
-
- iunlock(&tod);
}
+ iunlock(&tod);
}
long
--
⑨