Actual source code: psleep.c

petsc-3.7.7 2017-09-25
Report Typos and Errors
  2: #include <petscsys.h>                 /*I   "petscsys.h"    I*/
  3: #if defined(PETSC_HAVE_UNISTD_H)
  4: #include <unistd.h>
  5: #endif
  6: #if defined(PETSC_HAVE_DOS_H)    /* borland */
  7: #include <dos.h>
  8: #endif
  9: #if defined(PETSC_HAVE_TIME_H)
 10: #include <time.h>
 11: #endif

 15: /*@
 16:    PetscSleep - Sleeps some number of seconds.

 18:    Not Collective

 20:    Input Parameters:
 21: .  s - number of seconds to sleep

 23:    Notes:
 24:       If s is negative waits for keyboard input

 26:    Level: intermediate

 28:    Concepts: sleeping
 29:    Concepts: pause
 30:    Concepts: waiting

 32: @*/
 33: PetscErrorCode  PetscSleep(PetscReal s)
 34: {
 36:   if (s < 0) getc(stdin);

 38:   /* Some systems consider it an error to call nanosleep or usleep for more than one second so we only use them for subsecond sleeps. */
 39: #if defined(PETSC_HAVE_NANOSLEEP)
 40:   else if (s < 1) {
 41:     struct timespec rq;
 42:     rq.tv_sec  = 0;
 43:     rq.tv_nsec = (long)(s*1e9);
 44:     nanosleep(&rq,0);
 45:   }
 46: #elif defined(PETSC_HAVE_USLEEP)
 47:   /* POSIX.1-2001 deprecates this in favor of nanosleep because nanosleep defines interaction with signals */
 48:   else if (s < 1) usleep((unsigned int)(s*1e6));
 49: #endif

 51: #if defined(PETSC_HAVE_SLEEP)
 52:   else sleep((int)s);
 53: #elif defined(PETSC_HAVE__SLEEP) && defined(PETSC_HAVE__SLEEP_MILISEC)
 54:   else _sleep((int)(s*1000));
 55: #elif defined(PETSC_HAVE__SLEEP)
 56:   else _sleep((int)s);
 57: #else
 58:   SETERRQ(PETSC_COMM_SELF,PETSC_ERR_SUP_SYS,"No support for sleep() on this machine");
 59: #endif
 60:   return(0);
 61: }