summaryrefslogtreecommitdiff
path: root/sys/src/cmd/sleep.c
diff options
context:
space:
mode:
authorcinap_lenrek <cinap_lenrek@felloff.net>2022-12-18 22:33:36 +0000
committercinap_lenrek <cinap_lenrek@felloff.net>2022-12-18 22:33:36 +0000
commite51c4bc6e493a9cd0d9e9d7f1d24c57ae77bab65 (patch)
treeb2835b396c33c1d9da85a8ecf16430757740593c /sys/src/cmd/sleep.c
parent5a50a0df165c237503a922a7496c37690c9d4d0b (diff)
sleep: long sleep
Instead of waking up every second, sleep the maximum amount possible for long timeouts. Waking up every second is slow with thousands of processes hammering the timer.
Diffstat (limited to 'sys/src/cmd/sleep.c')
-rw-r--r--sys/src/cmd/sleep.c21
1 files changed, 13 insertions, 8 deletions
diff --git a/sys/src/cmd/sleep.c b/sys/src/cmd/sleep.c
index 0a8673bda..56f7b8bd7 100644
--- a/sys/src/cmd/sleep.c
+++ b/sys/src/cmd/sleep.c
@@ -4,34 +4,39 @@
void
main(int argc, char *argv[])
{
- long n;
+ enum { MAXSEC = 0x7fffffff/1000 };
+ long n, m;
char *p, *q;
if(argc>1){
- for(n = strtol(argv[1], &p, 0); n > 0; n--)
- sleep(1000);
+ for(n = strtol(argv[1], &p, 0); n > MAXSEC; n -= MAXSEC)
+ sleep(MAXSEC*1000);
/*
* no floating point because it is useful to
* be able to run sleep when bootstrapping
* a machine.
*/
- if(*p++ == '.' && (n = strtol(p, &q, 10)) > 0){
+ if(*p++ == '.' && (m = strtol(p, &q, 10)) > 0){
switch(q - p){
case 0:
break;
case 1:
- n *= 100;
+ m *= 100;
break;
case 2:
- n *= 10;
+ m *= 10;
break;
default:
p[3] = 0;
- n = strtol(p, 0, 10);
+ m = strtol(p, 0, 10);
break;
}
- sleep(n);
+ } else {
+ m = 0;
}
+ m += n*1000;
+ if(m > 0)
+ sleep(m);
}
exits(0);
}