the time corrections must be interlocked. also, there's no need to expose the internal workings of time time mechanism. todo: using two seperate locks is probablly not a good idea. Reference: /n/atom/patch/applied2013/timclean Date: Thu Oct 3 16:31:14 CES 2013 Signed-off-by: quanstro@quanstro.net --- /sys/src/fs/port/time.c Thu Oct 3 16:29:10 2013 +++ /sys/src/fs/port/time.c Thu Oct 3 16:29:10 2013 @@ -1,6 +1,15 @@ #include "all.h" -typedef struct Toy Toy; +typedef struct Time Time; +typedef struct Toy Toy; + +struct Time { + Lock; + Timet lasttoy; + Timet bias; + Timet offset; +}; + struct Toy { Lock; Timet base; @@ -8,6 +17,7 @@ }; static Toy toy; +static Time tim; enum { T = 500000000, /* needs to be 0 mod HZ */ @@ -147,9 +157,12 @@ t = toytime(); while(tim.bias != 0) { /* adjust at rate 1 sec/min */ + ilock(&tim); dt = t - tim.lasttoy; - if(dt < MINUTE(1)) + if(dt < MINUTE(1)){ + iunlock(&tim); break; + } if(tim.bias >= 0) { tim.bias -= SECOND(1); tim.offset += SECOND(1); @@ -158,6 +171,7 @@ tim.offset -= SECOND(1); } tim.lasttoy += MINUTE(1); + iunlock(&tim); } return t + tim.offset; } @@ -165,15 +179,18 @@ void settime(Timet nt) { - Timet dt; + Timet dt, toy; dt = nt - time(); - tim.lasttoy = toytime(); + toy = toytime(); + ilock(&tim); + tim.lasttoy = toy; if(dt > MAXBIAS || dt < -MAXBIAS) { /* too much, just set it */ tim.bias = 0; tim.offset = nt - tim.lasttoy; } else tim.bias = dt; + iunlock(&tim); } void --- /sys/src/fs/port/all.h Thu Oct 3 16:29:11 2013 +++ /sys/src/fs/port/all.h Thu Oct 3 16:29:11 2013 @@ -35,7 +35,6 @@ Uid* uid; Userid* gidspace; Lock printing; -Time tim; File* files; Wpath* wpaths; Lock wpathlock; --- /sys/src/fs/port/portdat.h Thu Oct 3 16:29:13 2013 +++ /sys/src/fs/port/portdat.h Thu Oct 3 16:29:14 2013 @@ -94,7 +94,6 @@ typedef struct File File; typedef struct Chan Chan; typedef struct Cons Cons; -typedef struct Time Time; typedef struct Tm Tm; typedef struct Rtc Rtc; typedef struct Hiob Hiob; @@ -326,13 +325,6 @@ { char* name; Off startsb; -}; - -struct Time -{ - Timet lasttoy; - Timet bias; - Timet offset; }; /*