00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 
00021 
00022 
00023 #ifndef GLUE_TIME_H
00024 #define GLUE_TIME_H
00025 
00026 #ifdef WIN32
00027 #   include <windows.h>
00028 #   include <winbase.h>
00029 
00030    inline double the_time() {
00031        return double(GetTickCount())/1000.0;
00032    }
00033 
00034    inline void
00035    fsleep(double dur)
00036    {
00037       Sleep(dur * 1e3);
00038    }
00039 
00040 #else
00041 #include <unistd.h>   
00042 #include <sys/time.h>
00043 
00044    inline double the_time() {
00045        struct timeval ts; struct timezone tz;
00046        gettimeofday(&ts, &tz);
00047        return (double)(ts.tv_sec + ts.tv_usec/1e6);
00048    }
00049 
00050    inline void
00051    fsleep(double dur)
00052    {
00053       struct timeval timeout;
00054       double         sleep_time = dur * 1e6;
00055       timeout.tv_sec  = 0;
00056       
00057 #  if defined(sgi) || defined(__CYGWIN__) || defined(__APPLE__) || defined(MACOSX)
00058       timeout.tv_usec = (long) sleep_time;
00059 #  else
00060 #    ifdef linux
00061       timeout.tv_usec = (time_t) sleep_time;
00062 #    else
00063       timeout.tv_usec = (suseconds_t) sleep_time;
00064 #    endif
00065 #  endif
00066       select(FD_SETSIZE, 0, 0, 0, &timeout);
00067    }
00068 #endif
00069 
00070 
00071 #endif