Annotation of coherent/b/lib/libc/gen/sleep.c, revision 1.1.1.1

1.1       root        1: /*
                      2:  * Sleep -- suspent execution for interval
                      3:  * See that alarms previously
                      4:  * and intermediately set are properly handled.
                      5:  */
                      6: 
                      7: #include "signal.h"
                      8: 
                      9: extern int     func();         /* Allow pause to return */
                     10: 
                     11: sleep(sec)
                     12: register unsigned sec;
                     13: {
                     14:        register unsigned osec;
                     15:        int (*ofunc)();
                     16: 
                     17:        for (;;) {
                     18:                ofunc = signal(SIGALRM, func);
                     19:                osec = alarm(sec);
                     20:                if (sec == 0) {
                     21:                        break;
                     22:                } else if (osec == 0) {         /* No current alarm */
                     23:                        func(0);
                     24:                        break;
                     25:                } else if (osec < sec) {        /* Current alarm precedes us */
                     26:                        alarm(osec);
                     27:                        func(0);
                     28:                        (*ofunc)();
                     29:                        sec -= osec;
                     30:                        continue;
                     31:                } else if (osec == sec) {       /* Contemporaneous */
                     32:                        func(0);
                     33:                        (*ofunc)();
                     34:                        sec -= osec;
                     35:                        continue;
                     36:                } else if (osec > sec) {        /* Current alarm follows us */
                     37:                        osec -= sec;
                     38:                        func(0);
                     39:                        break;
                     40:                }
                     41:        }
                     42:        signal(SIGALRM, ofunc);
                     43:        alarm(osec);
                     44: }
                     45: 
                     46: /*
                     47:  * Called to wait for SIGALRM,
                     48:  * and to catch SIGALRM thus waking up the pause half.
                     49:  */
                     50: static
                     51: func(n)
                     52: int n;
                     53: {
                     54:        static int done;
                     55: 
                     56:        if (n == 0) {
                     57:                done = 0;
                     58:                do pause(); while (done == 0);
                     59:        } else {
                     60:                ++done;
                     61:        }
                     62: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.