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.
This commit is contained in:
cinap_lenrek 2014-08-16 21:04:41 +02:00
parent ce0b77e2b9
commit 773b57b676

View file

@ -198,11 +198,13 @@ todfix(void)
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 @@ if(x > 30000000000ULL) iprint("todfix %llud\n", x);
/* protect against overflows */
tod.last = ticks;
tod.off = x;
iunlock(&tod);
}
iunlock(&tod);
}
long