Bug 1349801: Make SleepMicro a method of SamplerThread. r=mstange

So that I can use mIntervalMicroseconds in a later patch.

--HG--
extra : rebase_source : bd7f3de95ca06c19b3572f20fed8f679600ebacb
This commit is contained in:
David Major 2017-05-16 11:03:33 -04:00
Родитель 6fa3cf9282
Коммит 8184a04278
4 изменённых файлов: 52 добавлений и 52 удалений

Просмотреть файл

@ -115,33 +115,6 @@ tgkill(pid_t tgid, pid_t tid, int signalno)
return syscall(SYS_tgkill, tgid, tid, signalno);
}
static void
SleepMicro(int aMicroseconds)
{
aMicroseconds = std::max(0, aMicroseconds);
if (aMicroseconds >= 1000000) {
// Use usleep for larger intervals, because the nanosleep
// code below only supports intervals < 1 second.
MOZ_ALWAYS_TRUE(!::usleep(aMicroseconds));
return;
}
struct timespec ts;
ts.tv_sec = 0;
ts.tv_nsec = aMicroseconds * 1000UL;
int rv = ::nanosleep(&ts, &ts);
while (rv != 0 && errno == EINTR) {
// Keep waiting in case of interrupt.
// nanosleep puts the remaining time back into ts.
rv = ::nanosleep(&ts, &ts);
}
MOZ_ASSERT(!rv, "nanosleep call failed");
}
class PlatformData
{
public:
@ -358,6 +331,33 @@ SamplerThread::Stop(PSLockRef aLock)
sigaction(SIGPROF, &mOldSigprofHandler, 0);
}
void
SamplerThread::SleepMicro(int aMicroseconds)
{
aMicroseconds = std::max(0, aMicroseconds);
if (aMicroseconds >= 1000000) {
// Use usleep for larger intervals, because the nanosleep
// code below only supports intervals < 1 second.
MOZ_ALWAYS_TRUE(!::usleep(aMicroseconds));
return;
}
struct timespec ts;
ts.tv_sec = 0;
ts.tv_nsec = aMicroseconds * 1000UL;
int rv = ::nanosleep(&ts, &ts);
while (rv != 0 && errno == EINTR) {
// Keep waiting in case of interrupt.
// nanosleep puts the remaining time back into ts.
rv = ::nanosleep(&ts, &ts);
}
MOZ_ASSERT(!rv, "nanosleep call failed");
}
void
SamplerThread::SuspendAndSampleAndResumeThread(PSLockRef aLock,
TickSample& aSample)

Просмотреть файл

@ -37,18 +37,6 @@ Thread::GetCurrentId()
return gettid();
}
static void
SleepMicro(int 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
// merged with the linux-android version. Also, this doesn't handle the
// case where the usleep call is interrupted by a signal.
}
class PlatformData
{
public:
@ -109,6 +97,18 @@ SamplerThread::Stop(PSLockRef aLock)
MOZ_RELEASE_ASSERT(NS_IsMainThread());
}
void
SamplerThread::SleepMicro(int 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
// merged with the linux-android version. Also, this doesn't handle the
// case where the usleep call is interrupted by a signal.
}
void
SamplerThread::SuspendAndSampleAndResumeThread(PSLockRef aLock,
TickSample& aSample)

Просмотреть файл

@ -38,15 +38,6 @@ Thread::GetCurrentId()
return GetCurrentThreadId();
}
static void
SleepMicro(int aMicroseconds)
{
aMicroseconds = std::max(0, aMicroseconds);
int aMilliseconds = std::max(1, aMicroseconds / 1000);
::Sleep(aMilliseconds);
}
class PlatformData
{
public:
@ -156,6 +147,15 @@ SamplerThread::Stop(PSLockRef aLock)
}
}
void
SamplerThread::SleepMicro(int aMicroseconds)
{
aMicroseconds = std::max(0, aMicroseconds);
int aMilliseconds = std::max(1, aMicroseconds / 1000);
::Sleep(aMilliseconds);
}
void
SamplerThread::SuspendAndSampleAndResumeThread(PSLockRef aLock,
TickSample& aSample)

Просмотреть файл

@ -1685,10 +1685,6 @@ PrintUsageThenExit(int aExitCode)
////////////////////////////////////////////////////////////////////////
// BEGIN SamplerThread
// This suspends the calling thread for the given number of microseconds.
// Best effort timing.
static void SleepMicro(int aMicroseconds);
#if defined(GP_OS_linux) || defined(GP_OS_android)
struct SigHandlerCoordinator;
#endif
@ -1716,6 +1712,10 @@ public:
void Stop(PSLockRef aLock);
private:
// This suspends the calling thread for the given number of microseconds.
// Best effort timing.
void SleepMicro(int aMicroseconds);
// The activity generation, for detecting when the sampler thread must stop.
const uint32_t mActivityGeneration;