Main Page   Class Hierarchy   Compound List   File List   Compound Members   File Members  

time.H

Go to the documentation of this file.
00001 /*
00002  * Copyright 1997, Brown University, Providence, RI.
00003  * 
00004  *                         All Rights Reserved
00005  * 
00006  * Permission to use, copy, modify, and distribute this software and its
00007  * documentation for any purpose other than its incorporation into a
00008  * commercial product is hereby granted without fee, provided that the
00009  * above copyright notice appear in all copies and that both that
00010  * copyright notice and this permission notice appear in supporting
00011  * documentation, and that the name of Brown University not be used in
00012  * advertising or publicity pertaining to distribution of the software
00013  * without specific, written prior permission.
00014  * 
00015  * BROWN UNIVERSITY DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
00016  * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR ANY
00017  * PARTICULAR PURPOSE.  IN NO EVENT SHALL BROWN UNIVERSITY BE LIABLE FOR
00018  * ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
00019  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
00020  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
00021  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
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>   // for fd_set
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       // XXX - there should be a better way to avoid warnings
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

Generated on Mon Sep 15 16:25:57 2003 for gluebase by doxygen1.2.18