Fixing bug 43939 - timer leaks on Linux. r=scc.

This commit is contained in:
bryner%uiuc.edu 2000-06-27 23:25:32 +00:00
Родитель 4d63a53c92
Коммит bed079a93f
2 изменённых файлов: 31 добавлений и 16 удалений

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

@ -40,6 +40,12 @@ TimeVal::TimeVal()
mUSeconds = 0;
}
TimeVal::TimeVal(const TimeVal &tv)
{
mSeconds = tv.mSeconds;
mUSeconds = tv.mUSeconds;
}
TimeVal::~TimeVal()
{
@ -51,6 +57,28 @@ void TimeVal::Set(PRUint32 sec, PRUint32 usec)
mUSeconds = usec;
}
TimeVal& TimeVal::operator+=(PRInt32 msec) {
mSeconds += (PRUint32)(msec / 1000);
mUSeconds += (msec % 1000) * 1000;
if (mUSeconds > 1000000) {
mUSeconds -= 1000000;
mSeconds ++;
}
return *this;
}
TimeVal operator+(const TimeVal& lhs, PRInt32 rhs)
{
return TimeVal(lhs) += rhs;
}
TimeVal operator+(PRInt32 lhs, const TimeVal& rhs)
{
return TimeVal(rhs) += lhs;
}
TimeVal& TimeVal::operator=(const struct timeval &tv)
{
mSeconds = tv.tv_sec;
@ -58,21 +86,6 @@ TimeVal& TimeVal::operator=(const struct timeval &tv)
return *this;
}
TimeVal TimeVal::operator+(PRUint32 msec) const
{
TimeVal *t = new TimeVal(*this);
t->mSeconds += (PRUint32)(msec / 1000);
t->mUSeconds += (msec % 1000) * 1000;
if (t->mUSeconds >= 1000000) {
t->mUSeconds -= 1000000;
t->mSeconds++;
}
return *t;
}
PRBool TimeVal::operator==(const TimeVal &tv) const
{
return ((this->mSeconds == tv.mSeconds) && (this->mUSeconds == tv.mUSeconds));

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

@ -41,13 +41,15 @@ class nsVoidArray;
class TimeVal {
public:
TimeVal();
TimeVal(const TimeVal& rv); // copy constructor
virtual ~TimeVal();
void Set(PRUint32 sec, PRUint32 usec);
TimeVal& operator+=(PRInt32 msec);
TimeVal& operator=(const struct timeval &);
TimeVal operator+(PRUint32 msec) const; // this is a special class. only add milli secs to it.
PRBool operator==(const TimeVal &) const;
PRBool operator==(const struct timeval &) const;