mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 906754 - Ensure that TimeStamp's static fields are initialized only once. r=froydnj
This commit is contained in:
parent
c44d0d7b14
commit
d48fd3d8ac
@ -13,15 +13,41 @@
|
||||
|
||||
namespace mozilla {
|
||||
|
||||
TimeStamp TimeStamp::sFirstTimeStamp;
|
||||
TimeStamp TimeStamp::sProcessCreation;
|
||||
/**
|
||||
* Wrapper class used to initialize static data used by the TimeStamp class
|
||||
*/
|
||||
struct TimeStampInitialization {
|
||||
/**
|
||||
* First timestamp taken when the class static initializers are run. This
|
||||
* timestamp is used to sanitize timestamps coming from different sources.
|
||||
*/
|
||||
TimeStamp mFirstTimeStamp;
|
||||
|
||||
/**
|
||||
* Timestamp representing the time when the process was created. This field
|
||||
* is populated lazily the first time this information is required and is
|
||||
* replaced every time the process is restarted.
|
||||
*/
|
||||
TimeStamp mProcessCreation;
|
||||
|
||||
TimeStampInitialization() {
|
||||
TimeStamp::Startup();
|
||||
mFirstTimeStamp = TimeStamp::Now();
|
||||
};
|
||||
|
||||
~TimeStampInitialization() {
|
||||
TimeStamp::Shutdown();
|
||||
};
|
||||
};
|
||||
|
||||
static TimeStampInitialization sInitOnce;
|
||||
|
||||
TimeStamp
|
||||
TimeStamp::ProcessCreation(bool& aIsInconsistent)
|
||||
{
|
||||
aIsInconsistent = false;
|
||||
|
||||
if (sProcessCreation.IsNull()) {
|
||||
if (sInitOnce.mProcessCreation.IsNull()) {
|
||||
char *mozAppRestart = PR_GetEnv("MOZ_APP_RESTART");
|
||||
TimeStamp ts;
|
||||
|
||||
@ -31,32 +57,32 @@ TimeStamp::ProcessCreation(bool& aIsInconsistent)
|
||||
if (mozAppRestart && (strcmp(mozAppRestart, "") != 0)) {
|
||||
/* Firefox was restarted, use the first time-stamp we've taken as the new
|
||||
* process startup time. */
|
||||
ts = sFirstTimeStamp;
|
||||
ts = sInitOnce.mFirstTimeStamp;
|
||||
} else {
|
||||
TimeStamp now = Now();
|
||||
uint64_t uptime = ComputeProcessUptime();
|
||||
|
||||
ts = now - TimeDuration::FromMicroseconds(uptime);
|
||||
|
||||
if ((ts > sFirstTimeStamp) || (uptime == 0)) {
|
||||
if ((ts > sInitOnce.mFirstTimeStamp) || (uptime == 0)) {
|
||||
/* If the process creation timestamp was inconsistent replace it with
|
||||
* the first one instead and notify that a telemetry error was
|
||||
* detected. */
|
||||
aIsInconsistent = true;
|
||||
ts = sFirstTimeStamp;
|
||||
ts = sInitOnce.mFirstTimeStamp;
|
||||
}
|
||||
}
|
||||
|
||||
sProcessCreation = ts;
|
||||
sInitOnce.mProcessCreation = ts;
|
||||
}
|
||||
|
||||
return sProcessCreation;
|
||||
return sInitOnce.mProcessCreation;
|
||||
}
|
||||
|
||||
void
|
||||
TimeStamp::RecordProcessRestart()
|
||||
{
|
||||
sProcessCreation = TimeStamp();
|
||||
sInitOnce.mProcessCreation = TimeStamp();
|
||||
}
|
||||
|
||||
} // namespace mozilla
|
||||
|
@ -366,19 +366,6 @@ private:
|
||||
* When using a system clock, a value is system dependent.
|
||||
*/
|
||||
TimeStampValue mValue;
|
||||
|
||||
/**
|
||||
* First timestamp taken when the class static initializers are run. This
|
||||
* timestamp is used to sanitize timestamps coming from different sources.
|
||||
*/
|
||||
static TimeStamp sFirstTimeStamp;
|
||||
|
||||
/**
|
||||
* Timestamp representing the time when the process was created. This field
|
||||
* is populated lazily the first time this information is required and is
|
||||
* replaced every time the process is restarted.
|
||||
*/
|
||||
static TimeStamp sProcessCreation;
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -112,18 +112,6 @@ TimeDuration::Resolution()
|
||||
return TimeDuration::FromTicks(int64_t(sResolution));
|
||||
}
|
||||
|
||||
struct TimeStampInitialization
|
||||
{
|
||||
TimeStampInitialization() {
|
||||
TimeStamp::Startup();
|
||||
}
|
||||
~TimeStampInitialization() {
|
||||
TimeStamp::Shutdown();
|
||||
}
|
||||
};
|
||||
|
||||
static TimeStampInitialization initOnce;
|
||||
|
||||
nsresult
|
||||
TimeStamp::Startup()
|
||||
{
|
||||
@ -150,8 +138,6 @@ TimeStamp::Startup()
|
||||
sResolutionSigDigs *= 10);
|
||||
|
||||
gInitialized = true;
|
||||
sFirstTimeStamp = TimeStamp::Now();
|
||||
sProcessCreation = TimeStamp();
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
@ -160,17 +160,6 @@ TimeDuration::Resolution()
|
||||
return TimeDuration::FromTicks(int64_t(sResolution));
|
||||
}
|
||||
|
||||
struct TimeStampInitialization
|
||||
{
|
||||
TimeStampInitialization() {
|
||||
TimeStamp::Startup();
|
||||
}
|
||||
~TimeStampInitialization() {
|
||||
TimeStamp::Shutdown();
|
||||
}
|
||||
};
|
||||
|
||||
static TimeStampInitialization initOnce;
|
||||
static bool gInitialized = false;
|
||||
|
||||
nsresult
|
||||
@ -193,8 +182,6 @@ TimeStamp::Startup()
|
||||
sResolutionSigDigs *= 10);
|
||||
|
||||
gInitialized = true;
|
||||
sFirstTimeStamp = TimeStamp::Now();
|
||||
sProcessCreation = TimeStamp();
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
@ -438,18 +438,6 @@ TimeDuration::Resolution()
|
||||
return TimeDuration::FromTicks(int64_t(sResolution));
|
||||
}
|
||||
|
||||
struct TimeStampInitialization
|
||||
{
|
||||
TimeStampInitialization() {
|
||||
TimeStamp::Startup();
|
||||
}
|
||||
~TimeStampInitialization() {
|
||||
TimeStamp::Shutdown();
|
||||
}
|
||||
};
|
||||
|
||||
static TimeStampInitialization initOnce;
|
||||
|
||||
static bool
|
||||
HasStableTSC()
|
||||
{
|
||||
@ -515,8 +503,6 @@ TimeStamp::Startup()
|
||||
|
||||
InitThresholds();
|
||||
InitResolution();
|
||||
sFirstTimeStamp = TimeStamp::Now();
|
||||
sProcessCreation = TimeStamp();
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user