Bug 1349801: Make aMicroseconds unsigned to avoid a bunch of checks. r=mstange

We already do a max(0,...) before calling anyway.

--HG--
extra : rebase_source : 6cb3fa135e87cb12152e5b2cc8c2a7640489a0c4
This commit is contained in:
David Major 2017-05-16 11:06:18 -04:00
parent 8184a04278
commit 546b2aa408
4 changed files with 6 additions and 11 deletions

View File

@ -332,10 +332,8 @@ SamplerThread::Stop(PSLockRef aLock)
}
void
SamplerThread::SleepMicro(int aMicroseconds)
SamplerThread::SleepMicro(uint32_t aMicroseconds)
{
aMicroseconds = std::max(0, aMicroseconds);
if (aMicroseconds >= 1000000) {
// Use usleep for larger intervals, because the nanosleep
// code below only supports intervals < 1 second.

View File

@ -98,10 +98,8 @@ SamplerThread::Stop(PSLockRef aLock)
}
void
SamplerThread::SleepMicro(int aMicroseconds)
SamplerThread::SleepMicro(uint32_t aMicroseconds)
{
aMicroseconds = std::max(0, aMicroseconds);
usleep(aMicroseconds);
// FIXME: the OSX 10.12 page for usleep says "The usleep() function is
// obsolescent. Use nanosleep(2) instead." This implementation could be

View File

@ -148,10 +148,9 @@ SamplerThread::Stop(PSLockRef aLock)
}
void
SamplerThread::SleepMicro(int aMicroseconds)
SamplerThread::SleepMicro(uint32_t aMicroseconds)
{
aMicroseconds = std::max(0, aMicroseconds);
int aMilliseconds = std::max(1, aMicroseconds / 1000);
int aMilliseconds = std::max(1u, aMicroseconds / 1000);
::Sleep(aMilliseconds);
}

View File

@ -1714,7 +1714,7 @@ public:
private:
// This suspends the calling thread for the given number of microseconds.
// Best effort timing.
void SleepMicro(int aMicroseconds);
void SleepMicro(uint32_t aMicroseconds);
// The activity generation, for detecting when the sampler thread must stop.
const uint32_t mActivityGeneration;
@ -1858,7 +1858,7 @@ SamplerThread::Run()
TimeDuration targetSleepDuration = targetSleepEndTime - beforeSleep;
double sleepTime = std::max(0.0, (targetSleepDuration -
lastSleepOvershoot).ToMicroseconds());
SleepMicro(static_cast<int>(sleepTime));
SleepMicro(static_cast<uint32_t>(sleepTime));
sampleStart = TimeStamp::Now();
lastSleepOvershoot =
sampleStart - (beforeSleep + TimeDuration::FromMicroseconds(sleepTime));