sleep.c

Go to the documentation of this file.
00001 #include "config.h"
00002 
00003 #ifdef HAVE_SYS_TYPES_H
00004 #include <sys/types.h>
00005 #endif
00006 
00007 #ifdef HAVE_SYS_TIMEB_H
00008 #include <sys/timeb.h>
00009 #endif
00010 
00011 #ifdef HAVE_UNISTD_H
00012 #include <unistd.h>
00013 #endif
00014 
00015 #if TIME_WITH_SYS_TIME
00016 #include <sys/time.h>
00017 #include <time.h>
00018 #else
00019 #if HAVE_SYS_TIME_H
00020 #include <sys/time.h>
00021 #else
00022 #include <time.h>
00023 #endif
00024 #endif
00025 #include "gis.h"
00026 
00027 /*******************************************************************************
00028 *       sleep_ltp       (see manual, Internal Functions)                <in>   *
00029 *        Sleeps for fractional seconds                                         *
00030 *                                                                              *
00031 *        parameters:  double tm      fractional time to sleep (.001 sec res)   *
00032 *                                                                              *
00033 *        Returns zero upon normal end-of-job (EOJ).                            *
00034 *                      j.dabritz  7/30/90                                      *
00035 *******************************************************************************/
00036 
00037 long sleep_ltp( double tm)
00038 {       
00039         double finish;
00040         double check;
00041 
00042         time_ltp(&check); 
00043         for(finish = check + tm;  check <= finish; time_ltp(&check))
00044                 sleep(0);
00045 
00046         return(0);
00047 }
00048 
00049 /*******************************************************************************
00050 *       time_ltp        (see manual, Internal Functions)                <in>   *
00051 *        Sets a double to the time in fractional seconds.                      *
00052 *                                                                              *
00053 *        parameters:  double *time    pointer to double to be set.             *
00054 *                                                                              *
00055 *        Returns zero upon normal end-of-job (EOJ).                            *
00056 *                      j.dabritz  7/30/90                                      *
00057 *******************************************************************************/
00058 
00059 #ifdef HAVE_GETTIMEOFDAY
00060 
00061 int time_ltp( double *time)
00062 {
00063         struct timeval tstruct;
00064 
00065         gettimeofday (&tstruct, NULL);
00066         *time = tstruct.tv_sec + tstruct.tv_usec / 1000000.0;
00067         return(0);
00068 }
00069 
00070 #else
00071 
00072 #ifdef HAVE_FTIME
00073 
00074 int time_ltp( double *time)
00075 {
00076         struct timeb tstruct;
00077 
00078         ftime(&tstruct);
00079         *time = tstruct.time + tstruct.millitm / 1000.0;
00080         return(0);
00081 }
00082 
00083 #else
00084 
00085 #ifdef HAVE_TIME
00086 
00087 int time_ltp(double *time)
00088 {
00089         time_t tloc;
00090 
00091         time(&tloc);  
00092         *time = tloc;  
00093         return(0);
00094 }
00095 
00096 #endif /* HAVE_TIME */
00097 #endif /* HAVE_FTIME */
00098 #endif /* HAVE_GETTIMEOFDAY */

Generated on Wed Aug 23 17:49:23 2006 for GRASS by  doxygen 1.4.7