home *** CD-ROM | disk | FTP | other *** search
/ The CDPD Public Domain Collection for CDTV 3 / CDPDIII.bin / pd / programming / gnuc / gen_library / rcs / sleep.c,v < prev    next >
Encoding:
Text File  |  1992-07-04  |  2.8 KB  |  107 lines

  1. head    1.1;
  2. access;
  3. symbols
  4.     version39-41:1.1;
  5. locks;
  6. comment    @ * @;
  7.  
  8.  
  9. 1.1
  10. date    92.06.08.18.31.20;    author mwild;    state Exp;
  11. branches;
  12. next    ;
  13.  
  14.  
  15. desc
  16. @initial checkin
  17. @
  18.  
  19.  
  20. 1.1
  21. log
  22. @Initial revision
  23. @
  24. text
  25. @/*
  26.  * Copyright (c) 1989 The Regents of the University of California.
  27.  * All rights reserved.
  28.  *
  29.  * Redistribution and use in source and binary forms are permitted
  30.  * provided that: (1) source distributions retain this entire copyright
  31.  * notice and comment, and (2) distributions including binaries display
  32.  * the following acknowledgement:  ``This product includes software
  33.  * developed by the University of California, Berkeley and its contributors''
  34.  * in the documentation or other materials provided with the distribution
  35.  * and in all advertising materials mentioning features or use of this
  36.  * software. Neither the name of the University nor the names of its
  37.  * contributors may be used to endorse or promote products derived
  38.  * from this software without specific prior written permission.
  39.  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
  40.  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
  41.  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  42.  */
  43.  
  44. #if defined(LIBC_SCCS) && !defined(lint)
  45. static char sccsid[] = "@@(#)sleep.c    5.5 (Berkeley) 6/1/90";
  46. #endif /* LIBC_SCCS and not lint */
  47.  
  48. #define KERNEL
  49. #include "ixemul.h"
  50. #include <sys/time.h>
  51.  
  52. #define    setvec(vec, a) \
  53.     vec.sv_handler = a; vec.sv_mask = vec.sv_onstack = 0
  54.  
  55. #define ringring u.u_ringring
  56.  
  57. int
  58. sleep(unsigned int seconds)
  59. {
  60.     register struct itimerval *itp;
  61.     struct itimerval itv, oitv;
  62.     struct sigvec vec, ovec;
  63.     long omask;
  64.     void sleephandler();
  65.  
  66.     itp = &itv;
  67.     if (!seconds)
  68.         return -1;
  69.     timerclear(&itp->it_interval);
  70.     timerclear(&itp->it_value);
  71.     if (syscall (SYS_setitimer, ITIMER_REAL, itp, &oitv) < 0)
  72.         return -1;
  73.     itp->it_value.tv_sec = seconds;
  74.     if (timerisset(&oitv.it_value)) {
  75.         if (timercmp(&oitv.it_value, &itp->it_value, >))
  76.             oitv.it_value.tv_sec -= itp->it_value.tv_sec;
  77.         else {
  78.             itp->it_value = oitv.it_value;
  79.             /*
  80.              * This is a hack, but we must have time to return
  81.              * from the setitimer after the alarm or else it'll
  82.              * be restarted.  And, anyway, sleep never did
  83.              * anything more than this before.
  84.              */
  85.             oitv.it_value.tv_sec = 1;
  86.             oitv.it_value.tv_usec = 0;
  87.         }
  88.     }
  89.     setvec(vec, sleephandler);
  90.     (void) syscall (SYS_sigvec, SIGALRM, &vec, &ovec);
  91.     omask = syscall (SYS_sigblock, sigmask(SIGALRM));
  92.     ringring = 0;
  93.     (void) syscall (SYS_setitimer, ITIMER_REAL, itp, (struct itimerval *)0);
  94.     while (!ringring)
  95.         syscall (SYS_sigpause, omask &~ sigmask(SIGALRM));
  96.     (void) syscall (SYS_sigvec, SIGALRM, &ovec, (struct sigvec *)0);
  97.     (void) syscall (SYS_sigsetmask, omask);
  98.     (void) syscall (SYS_setitimer, ITIMER_REAL, &oitv, (struct itimerval *)0);
  99. }
  100.  
  101. static void
  102. sleephandler()
  103. {
  104.     ringring = 1;
  105. }
  106. @
  107.