cleanup nsec not to cache anything. Reference: /n/patches.lsub.org/patch/nsec Date: Sun Apr 15 12:51:58 CES 2012 Signed-off-by: nemo@lsub.org --- /sys/src/libc/9sys/nsec.c Thu Apr 12 12:26:16 2012 +++ /sys/src/libc/9sys/nsec.c Wed Apr 11 19:38:03 2012 @@ -16,60 +16,19 @@ t[o[i]] = f[i]; } -static int fd = -1; -static struct { - int pid; - int fd; -} fds[64]; - vlong nsec(void) { uchar b[8]; vlong t; - int pid, i, f, tries; - - /* - * Threaded programs may have multiple procs - * with different fd tables, so we may need to open - * /dev/bintime on a per-pid basis - */ + int f; - /* First, look if we've opened it for this particular pid */ - pid = _tos->pid; - do{ - f = -1; - for(i = 0; i < nelem(fds); i++) - if(fds[i].pid == pid){ - f = fds[i].fd; - break; - } - tries = 0; - if(f < 0){ - /* If it's not open for this pid, try the global pid */ - if(fd >= 0) - f = fd; - else{ - /* must open */ - if((f = open("/dev/bintime", OREAD|OCEXEC)) < 0) - return 0; - fd = f; - for(i = 0; i < nelem(fds); i++) - if(fds[i].pid == pid || fds[i].pid == 0){ - fds[i].pid = pid; - fds[i].fd = f; - break; - } - } - } - if(pread(f, b, sizeof b, 0) == sizeof b){ - be2vlong(&t, b); - return t; - } - close(f); - if(i < nelem(fds)) - fds[i].fd = -1; - }while(tries++ == 0); /* retry once */ - USED(tries); - return 0; + f = open("/dev/bintime", OREAD); + if(f < 0) + return 0; + t = 0; + if(pread(f, b, sizeof b, 0) == sizeof b) + be2vlong(&t, b); + close(f); + return t; }