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:
parent
ce0b77e2b9
commit
773b57b676
1 changed files with 5 additions and 4 deletions
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue