diff options
author | cinap_lenrek <cinap_lenrek@felloff.net> | 2016-04-10 02:52:31 +0200 |
---|---|---|
committer | cinap_lenrek <cinap_lenrek@felloff.net> | 2016-04-10 02:52:31 +0200 |
commit | 5e37087451d857f3d329341319511d00f0c49c38 (patch) | |
tree | 29de45583b7b71cf158e3fe37295517df8dedae2 /sys/src/ape | |
parent | 3ba1197aeb382e1750cbb0f2567794bd4482e1e2 (diff) |
ape: add internal _NSEC() function and make gettimeofday() use it
Diffstat (limited to 'sys/src/ape')
-rw-r--r-- | sys/src/ape/lib/ap/plan9/9nsec.c | 43 | ||||
-rw-r--r-- | sys/src/ape/lib/ap/plan9/mkfile | 1 | ||||
-rw-r--r-- | sys/src/ape/lib/bsd/gettimeofday.c | 41 |
3 files changed, 48 insertions, 37 deletions
diff --git a/sys/src/ape/lib/ap/plan9/9nsec.c b/sys/src/ape/lib/ap/plan9/9nsec.c new file mode 100644 index 000000000..87d2e8a68 --- /dev/null +++ b/sys/src/ape/lib/ap/plan9/9nsec.c @@ -0,0 +1,43 @@ +#include "sys9.h" + +typedef unsigned long long uvlong; +typedef long long vlong; +typedef unsigned char uchar; + +static uvlong order = 0x0001020304050607ULL; + +static void +be2vlong(vlong *to, uchar *f) +{ + uchar *t, *o; + int i; + + t = (uchar*)to; + o = (uchar*)ℴ + for(i = 0; i < 8; i++) + t[o[i]] = f[i]; +} + +long long +_NSEC(void) +{ + uchar b[8]; + vlong t; + int opened; + static int fd = -1; + + opened = 0; + for(;;) { + if(fd < 0) + if(opened++ || + (fd = _OPEN("/dev/bintime", OREAD|OCEXEC)) < 0) + return 0; + if(_PREAD(fd, b, sizeof b, 0) == sizeof b) + break; /* leave fd open for future use */ + /* short read, perhaps try again */ + _CLOSE(fd); + fd = -1; + } + be2vlong(&t, b); + return t; +} diff --git a/sys/src/ape/lib/ap/plan9/mkfile b/sys/src/ape/lib/ap/plan9/mkfile index 502d00f8b..1da4318a4 100644 --- a/sys/src/ape/lib/ap/plan9/mkfile +++ b/sys/src/ape/lib/ap/plan9/mkfile @@ -11,6 +11,7 @@ OFILES=\ _getpw.$O\ _nap.$O\ 9mallocz.$O\ + 9nsec.$O\ 9iounit.$O\ 9read.$O\ 9readn.$O\ diff --git a/sys/src/ape/lib/bsd/gettimeofday.c b/sys/src/ape/lib/bsd/gettimeofday.c index ee347f36a..4de4973c1 100644 --- a/sys/src/ape/lib/bsd/gettimeofday.c +++ b/sys/src/ape/lib/bsd/gettimeofday.c @@ -1,49 +1,16 @@ #include <sys/types.h> #include <time.h> #include <sys/time.h> -#include <string.h> -#include "sys9.h" -typedef unsigned long long uvlong; -typedef long long vlong; -typedef unsigned char uchar; - -static uvlong order = 0x0001020304050607ULL; - -static void -be2vlong(vlong *to, uchar *f) -{ - uchar *t, *o; - int i; - - t = (uchar*)to; - o = (uchar*)ℴ - for(i = 0; i < 8; i++) - t[o[i]] = f[i]; -} +/* ap/plan9/9nsec.c */ +extern long long _NSEC(void); int gettimeofday(struct timeval *tp, struct timezone *tzp) { - uchar b[8]; - vlong t; - int opened; - static int fd = -1; - - opened = 0; - for(;;) { - if(fd < 0) - if(opened++ || - (fd = _OPEN("/dev/bintime", OREAD|OCEXEC)) < 0) - return 0; - if(_PREAD(fd, b, sizeof b, 0) == sizeof b) - break; /* leave fd open for future use */ - /* short read, perhaps try again */ - _CLOSE(fd); - fd = -1; - } - be2vlong(&t, b); + long long t; + t = _NSEC(); tp->tv_sec = t/1000000000; tp->tv_usec = (t/1000)%1000000; |