1 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_STDLIB_H) 7 #include <stdlib.h> 8 #endif 9 #if defined (PETSC_HAVE_DOS_H) /* borland */ 10 #include <dos.h> 11 #endif 12 #if defined (PETSC_HAVE_TIME_H) 13 #include <time.h> 14 #endif 15 16 #undef __FUNCT__ 17 #define __FUNCT__ "PetscSleep" 18 /*@ 19 PetscSleep - Sleeps some number of seconds. 20 21 Not Collective 22 23 Input Parameters: 24 . s - number of seconds to sleep 25 26 Notes: 27 If s is negative waits for keyboard input 28 29 Level: intermediate 30 31 Concepts: sleeping 32 Concepts: pause 33 Concepts: waiting 34 35 @*/ 36 PetscErrorCode PetscSleep(PetscReal s) 37 { 38 PetscFunctionBegin; 39 if (s < 0) getc(stdin); 40 41 /* Some systems consider it an error to call nanosleep or usleep for more than one second so we only use them for subsecond sleeps. */ 42 #if defined (PETSC_HAVE_NANOSLEEP) 43 else if (s < 1) { 44 struct timespec rq; 45 rq.tv_sec = 0; 46 rq.tv_nsec = (long)(s*1e9); 47 nanosleep(&rq,0); 48 } 49 #elif defined (PETSC_HAVE_USLEEP) 50 /* POSIX.1-2001 deprecates this in favor of nanosleep because nanosleep defines interaction with signals */ 51 else if (s < 1) usleep((unsigned int)(s*1e6)); 52 #endif 53 54 #if defined (PETSC_HAVE_SLEEP) 55 else sleep((int)s); 56 #elif defined (PETSC_HAVE__SLEEP) && defined(PETSC_HAVE__SLEEP_MILISEC) 57 else _sleep((int)(s*1000)); 58 #elif defined (PETSC_HAVE__SLEEP) 59 else _sleep((int)s); 60 #else 61 SETERRQ(PETSC_COMM_SELF,PETSC_ERR_SUP_SYS,"No support for sleep() on this machine"); 62 #endif 63 PetscFunctionReturn(0); 64 } 65 66