Bug 822490 - Radically simplify windows TimeStamp implementation, r=tellrob

This commit is contained in:
Honza Bambas 2013-02-11 22:56:58 +01:00
parent 0d7005df64
commit b2f0520748
5 changed files with 559 additions and 669 deletions

View File

@ -11,6 +11,9 @@
#include "chrome/common/ipc_message_utils.h"
#include "mozilla/TimeStamp.h"
#ifdef XP_WIN
#include "mozilla/TimeStamp_windows.h"
#endif
#include "mozilla/Util.h"
#include "mozilla/gfx/2D.h"
#include "mozilla/StandardInteger.h"
@ -925,6 +928,30 @@ struct ParamTraits<mozilla::TimeStamp>
};
};
#ifdef XP_WIN
template<>
struct ParamTraits<mozilla::TimeStampValue>
{
typedef mozilla::TimeStampValue paramType;
static void Write(Message* aMsg, const paramType& aParam)
{
WriteParam(aMsg, aParam.mGTC);
WriteParam(aMsg, aParam.mQPC);
WriteParam(aMsg, aParam.mHasQPC);
WriteParam(aMsg, aParam.mIsNull);
}
static bool Read(const Message* aMsg, void** aIter, paramType* aResult)
{
return (ReadParam(aMsg, aIter, &aResult->mGTC) &&
ReadParam(aMsg, aIter, &aResult->mQPC) &&
ReadParam(aMsg, aIter, &aResult->mHasQPC) &&
ReadParam(aMsg, aIter, &aResult->mIsNull));
}
};
#endif
template <>
struct ParamTraits<mozilla::SerializedStructuredCloneBuffer>
{

View File

@ -59,6 +59,12 @@ EXPORTS_mozilla = \
StringBuilder.h \
$(NULL)
ifeq ($(OS_ARCH),WINNT)
EXPORTS_mozilla += \
TimeStamp_windows.h \
$(NULL)
endif
EXPORTS = \
nsArray.h \
nsAtomService.h \

View File

@ -16,8 +16,18 @@ namespace IPC {
template <typename T> struct ParamTraits;
}
#ifdef XP_WIN
// defines TimeStampValue as a complex value keeping both
// GetTickCount and QueryPerformanceCounter values
#include "TimeStamp_windows.h"
#endif
namespace mozilla {
#ifndef XP_WIN
typedef uint64_t TimeStampValue;
#endif
class TimeStamp;
/**
@ -150,7 +160,7 @@ private:
return TimeDuration::FromTicks(int64_t(aTicks));
}
// Duration in PRIntervalTime units
// Duration, result is implementation-specific difference of two TimeStamps
int64_t mValue;
};
@ -286,7 +296,7 @@ public:
private:
friend struct IPC::ParamTraits<mozilla::TimeStamp>;
TimeStamp(uint64_t aValue) : mValue(aValue) {}
TimeStamp(TimeStampValue aValue) : mValue(aValue) {}
/**
* When built with PRIntervalTime, a value of 0 means this instance
@ -301,7 +311,7 @@ private:
*
* When using a system clock, a value is system dependent.
*/
uint64_t mValue;
TimeStampValue mValue;
};
}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,58 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim:set ts=2 sw=2 sts=2 et cindent: */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef mozilla_TimeStamp_windows_h
#define mozilla_TimeStamp_windows_h
namespace mozilla {
class TimeStamp;
class TimeStampValue
{
friend struct IPC::ParamTraits<mozilla::TimeStampValue>;
friend class TimeStamp;
// Both QPC and GTC are kept in [mt] units.
uint64_t mGTC;
uint64_t mQPC;
bool mHasQPC;
bool mIsNull;
TimeStampValue(uint64_t GTC, uint64_t QPC, bool hasQPC);
bool CheckQPC(int64_t aDuration, const TimeStampValue &aOther) const;
public:
struct _SomethingVeryRandomHere;
TimeStampValue(_SomethingVeryRandomHere* nullValue);
uint64_t operator-(const TimeStampValue &aOther) const;
TimeStampValue operator+(const int64_t aOther) const
{ return TimeStampValue(mGTC + aOther, mQPC + aOther, mHasQPC); }
TimeStampValue operator-(const int64_t aOther) const
{ return TimeStampValue(mGTC - aOther, mQPC - aOther, mHasQPC); }
TimeStampValue& operator+=(const int64_t aOther);
TimeStampValue& operator-=(const int64_t aOther);
bool operator<(const TimeStampValue &aOther) const
{ return int64_t(*this - aOther) < 0; }
bool operator>(const TimeStampValue &aOther) const
{ return int64_t(*this - aOther) > 0; }
bool operator<=(const TimeStampValue &aOther) const
{ return int64_t(*this - aOther) <= 0; }
bool operator>=(const TimeStampValue &aOther) const
{ return int64_t(*this - aOther) >= 0; }
bool operator==(const TimeStampValue &aOther) const
{ return int64_t(*this - aOther) == 0; }
bool operator!=(const TimeStampValue &aOther) const
{ return int64_t(*this - aOther) != 0; }
};
}
#endif /* mozilla_TimeStamp_h */