diff options
author | Thomas Grill <xovo@users.sourceforge.net> | 2005-05-23 16:52:46 +0000 |
---|---|---|
committer | Thomas Grill <xovo@users.sourceforge.net> | 2005-05-23 16:52:46 +0000 |
commit | a1c2bb17663ce4dea2f5e7e3c1e1bfae35541a2c (patch) | |
tree | 9000122288ab01e7d815323c79342f668d6b2a5b /externals/grill/flext/source/fltimer.cpp | |
parent | a98acaeb0ce114ede2cfd31267c6dcc3fc0fbb01 (diff) |
oops, fix
Max/MSP has its own check....
changed initialization functions accordingly
better timers for Windows
fixed timer bug
changed template parameter of TableMap
compiler flag for MinGW binary compatibility (thanks to GG)
enable WIN2000/XP API features with definition in build system
fix for symbol messages into non-left inlets
restructured TableMap type (doesn't own pointers any more)
no sanity check for iterator
fixes for MSVC6
slimmed object data structures
better c++ compliance
fixed problems with symbol binding
svn path=/trunk/; revision=3074
Diffstat (limited to 'externals/grill/flext/source/fltimer.cpp')
-rwxr-xr-x | externals/grill/flext/source/fltimer.cpp | 70 |
1 files changed, 55 insertions, 15 deletions
diff --git a/externals/grill/flext/source/fltimer.cpp b/externals/grill/flext/source/fltimer.cpp index c33716e5..d9bf3cc1 100755 --- a/externals/grill/flext/source/fltimer.cpp +++ b/externals/grill/flext/source/fltimer.cpp @@ -50,11 +50,20 @@ double flext::GetTimeGrain() #endif } +#if FLEXT_OS == FLEXT_OS_WIN +static double perffrq = 0; +#endif + static double getstarttime(); static double starttime = getstarttime(); static double getstarttime() { +#if FLEXT_OS == FLEXT_OS_WIN + LARGE_INTEGER frq; + if(QueryPerformanceFrequency(&frq)) perffrq = (double)frq.QuadPart; +#endif + starttime = 0; return flext::GetOSTime(); } @@ -64,15 +73,15 @@ double flext::GetOSTime() double tm; #if FLEXT_OS == FLEXT_OS_WIN - LARGE_INTEGER frq,cnt; - if(QueryPerformanceFrequency(&frq) && QueryPerformanceCounter(&cnt)) - tm = (double)(cnt.QuadPart)/frq.QuadPart; + LARGE_INTEGER cnt; + if(perffrq && QueryPerformanceCounter(&cnt)) + tm = cnt.QuadPart/perffrq; else { SYSTEMTIME systm; FILETIME fltm; GetSystemTime(&systm); SystemTimeToFileTime(&systm,&fltm); - tm = (double)((LARGE_INTEGER *)&fltm)->QuadPart*0.001; + tm = ((LARGE_INTEGER *)&fltm)->QuadPart*1.e-7; } #elif FLEXT_OS == FLEXT_OS_LINUX || FLEXT_OS == FLEXT_OS_IRIX || FLEXT_OSAPI == FLEXT_OSAPI_MAC_MACH // POSIX timeval tmv; @@ -90,8 +99,39 @@ double flext::GetOSTime() void flext::Sleep(double s) { + if(s <= 0) return; #if FLEXT_OS == FLEXT_OS_WIN - ::Sleep((long)(s*1000.)); +#if defined(_WIN32_WINNT) && _WIN32_WINNT >= 0x400 +#if 0 + LARGE_INTEGER liDueTime; + liDueTime.QuadPart = (LONGLONG)(-1.e7*s); + + // Create a waitable timer. + HANDLE hTimer = CreateWaitableTimer(NULL,TRUE,NULL); + if(hTimer) { + if(SetWaitableTimer(hTimer,&liDueTime,0,NULL,NULL,0)) + // Wait for the timer. + WaitForSingleObject(hTimer,INFINITE); // != WAIT_OBJECT_0) + else + ::Sleep((long)(s*1000.)); + CloseHandle(hTimer); + } + else +#else + LARGE_INTEGER cnt; + if(perffrq && QueryPerformanceCounter(&cnt)) { + LONGLONG dst = (LONGLONG)(cnt.QuadPart+perffrq*s); + for(;;) { + SwitchToThread(); // while waiting switch to another thread + QueryPerformanceCounter(&cnt); + if(cnt.QuadPart > dst) break; + } + } + else +#endif +#endif + // last resort.... + ::Sleep((long)(s*1000.)); #elif FLEXT_OS == FLEXT_OS_LINUX || FLEXT_OS == FLEXT_OS_IRIX || FLEXT_OSAPI == FLEXT_OSAPI_MAC_MACH // POSIX usleep((long)(s*1000000.)); #elif FLEXT_OS == FLEXT_OS_MAC // that's just for OS9 & Carbon! @@ -234,14 +274,12 @@ void flext::Timer::callback(Timer *tmr) #endif } - if(tmr->cback) { #if FLEXT_SYS == FLEXT_SYS_MAX - if(tmr->queued) - qelem_set(tmr->qelem); - else + if(tmr->queued) + qelem_set(tmr->qelem); + else #endif - tmr->Work(); - } + tmr->Work(); } #if FLEXT_SYS == FLEXT_SYS_MAX @@ -255,9 +293,11 @@ void flext::Timer::queuefun(Timer *tmr) { tmr->Work(); } */ void flext::Timer::Work() { - if(clss) - ((bool (*)(flext_base *,void *))cback)(clss,userdata); - else - cback(userdata); + if(cback) { + if(clss) + ((bool (*)(flext_base *,void *))cback)(clss,userdata); + else + cback(userdata); + } } |