Main Page | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Class Members | File Members | Related Pages

PhxTimer.h

00001 #ifndef PHX_TIMER_H
00002 #define PHX_TIMER_H
00003 //
00004 #include <windows.h>
00005 #include <MMSystem.h>
00006 
00007 namespace Phx {
00008 
00009 class Timer
00010 {
00011 public:
00012         
00013         static long getTime()
00014         {
00015         #ifdef WIN32
00016 
00017                 LARGE_INTEGER freq;
00018                 if ( QueryPerformanceFrequency(&freq) )
00019                 {
00020                         LARGE_INTEGER counter;
00021                         QueryPerformanceCounter( &counter );
00022                         if ( freq.QuadPart >= 1000 )
00023                         {
00024                                 // resolution is more than 1ms
00025                                 __int64 msDiv = __int64(freq.QuadPart) / __int64(1000);
00026                                 __int64 c = __int64(counter.QuadPart) / msDiv;
00027                                 return (long)c;
00028                         }
00029                 }
00030 
00031                 return timeGetTime();
00032 
00033         #else
00034 
00035                 double t = double(clock()) / double(CLOCKS_PER_SEC) * 1000.0;
00036                 return (long)t;
00037 
00038         #endif
00039         }
00040 
00041         // sleep for x milliseconds
00042         static int Sleep(long time)
00043         {
00044         #ifdef WIN32
00045                 //std::clog << "Sleeping for " << time << " milliseconds." << std::endl;
00046                 ::Sleep(time);
00047                 //std::clog << "Ending Sleep" << std::endl;
00048         #else
00049                 struct timespec tv;     
00050                 tv.tv_sec = 0; 
00051                 tv.tv_nsec = time;
00052                 nanosleep(&tv, 0);
00053                 
00054         #endif
00055                 return 0;
00056         }
00057 };
00058 
00059 } // end namespace OSFSUtil
00060 
00061 #endif

Generated on Mon Jul 10 19:45:29 2006 for Phoenix OSFS by  doxygen 1.4.2