[AD] windows time functions |
[ Thread Index |
Date Index
| More lists.liballeg.org/allegro-developers Archives
]
/4.9.2/src/win/wtime.c
in function:
unsigned long al_current_time(void)
{
/* XXX: Maybe use QueryPerformanceCounter? */
return timeGetTime() - _al_win_initial_time;
}
more comments:
QueryPerformanceCounter, obtains its value from the CPU upon which the
current thread is running.
If the thread switches to another CPU, it is possibly for the value to
completely change.
There are currently no intelligent solutions to this problem.
Some solutions i have heard of:
- Mask the calling thread to a specific CPU, (which kind of defeats
the point in having multi-processor machines).
- Run it in a thread that is locked to a specific CPU, and use
CriticalSections to access it.. ( which defeats the
Query[Performace]Counter() )
QueryPerformanceCounter is also documented as jumping in value which
can create non-linear values being returned.
Problems with timeGetTime() :
unless you run the timeBeginTime() and timeEndTime()
timeGetTime()'s resolution can be as much as 8-10ms sloppy.
which for anything like trying to sync a screen draw/flip can cause
significant error in calculations.
al_current_time()'s wrap length. 49days :(
I know many (99.9%) of you are going to say "whose stupid enough to be
using an allegro app for 49 days"... well.. I do!
I do like the recently proposed solution on a.cc using a struct {
int32_t hi; uint32_t lo; } when lo wraps hi++ then accessor functions
_al_get_current_time32() { return t.lo; } and
_al_get_current_time64() { return (__int64)t; }
aj.