Additional comments regarding sleep implementation.
This commit is contained in:
parent
20db4969c5
commit
50332a8186
@ -39,12 +39,16 @@ void sleepImpl(Time time)
|
|||||||
{
|
{
|
||||||
Uint64 usecs = time.asMicroseconds();
|
Uint64 usecs = time.asMicroseconds();
|
||||||
|
|
||||||
// construct the time to wait
|
// Construct the time to wait
|
||||||
timespec ti;
|
timespec ti;
|
||||||
ti.tv_nsec = (usecs % 1000000) * 1000;
|
ti.tv_nsec = (usecs % 1000000) * 1000;
|
||||||
ti.tv_sec = usecs / 1000000;
|
ti.tv_sec = usecs / 1000000;
|
||||||
|
|
||||||
// wait...
|
// Wait...
|
||||||
|
// If nanosleep returns -1, we check errno. If it is EINTR
|
||||||
|
// nanosleep was interrupted and has set ti to the remaining
|
||||||
|
// duration. We continue sleeping until the complete duration
|
||||||
|
// has passed. We stop sleeping if it was due to an error.
|
||||||
while ((nanosleep(&ti, &ti) == -1) && (errno == EINTR))
|
while ((nanosleep(&ti, &ti) == -1) && (errno == EINTR))
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
@ -36,17 +36,17 @@ namespace priv
|
|||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
void sleepImpl(Time time)
|
void sleepImpl(Time time)
|
||||||
{
|
{
|
||||||
// get the supported timer resolutions on this system
|
// Get the supported timer resolutions on this system
|
||||||
TIMECAPS tc;
|
TIMECAPS tc;
|
||||||
timeGetDevCaps(&tc, sizeof(TIMECAPS));
|
timeGetDevCaps(&tc, sizeof(TIMECAPS));
|
||||||
|
|
||||||
// set the timer resolution to the minimum for the Sleep call
|
// Set the timer resolution to the minimum for the Sleep call
|
||||||
timeBeginPeriod(tc.wPeriodMin);
|
timeBeginPeriod(tc.wPeriodMin);
|
||||||
|
|
||||||
// wait...
|
// Wait...
|
||||||
::Sleep(time.asMilliseconds());
|
::Sleep(time.asMilliseconds());
|
||||||
|
|
||||||
// reset the timer resolution back to the system default
|
// Reset the timer resolution back to the system default
|
||||||
timeEndPeriod(tc.wPeriodMin);
|
timeEndPeriod(tc.wPeriodMin);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user