From 7d21257e8a92171ced7bc38910d2e280c0df1085 Mon Sep 17 00:00:00 2001 From: Bill Joy Date: Fri, 23 Nov 1979 04:13:02 -0800 Subject: [PATCH] BSD 3 development Work on file usr/src/libc/gen/sleep.c Synthesized-from: 3bsd --- usr/src/libc/gen/sleep.c | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 usr/src/libc/gen/sleep.c diff --git a/usr/src/libc/gen/sleep.c b/usr/src/libc/gen/sleep.c new file mode 100644 index 0000000000..4226dc566e --- /dev/null +++ b/usr/src/libc/gen/sleep.c @@ -0,0 +1,40 @@ +#include +#include + +static jmp_buf jmp; + +sleep(n) +unsigned n; +{ + int sleepx(); + unsigned altime; + int (*alsig)() = SIG_DFL; + + if (n==0) + return; + altime = alarm(1000); /* time to maneuver */ + if (setjmp(jmp)) { + signal(SIGALRM, alsig); + alarm(altime); + return; + } + if (altime) { + if (altime > n) + altime -= n; + else { + n = altime; + altime = 1; + } + } + alsig = signal(SIGALRM, sleepx); + alarm(n); + for(;;) + pause(); + /*NOTREACHED*/ +} + +static +sleepx() +{ + longjmp(jmp, 1); +} -- 2.20.1