diff options
author | Chris Wilson <chris+github@qwirx.com> | 2012-02-12 12:29:56 +0000 |
---|---|---|
committer | Chris Wilson <chris+github@qwirx.com> | 2012-02-12 12:29:56 +0000 |
commit | 15a3e05144785bfcaddcf2d11b6c549edd9f62ee (patch) | |
tree | 30827463c74a3b24f4b206894580a4511203c014 /lib/common | |
parent | 03d7cb4d75822b40d263d0737e3115a0aeff1cda (diff) |
Add experimental "TCP Nice" mode, disabled by default.
Diffstat (limited to 'lib/common')
-rw-r--r-- | lib/common/BoxTime.h | 4 | ||||
-rw-r--r-- | lib/common/Timer.cpp | 38 | ||||
-rw-r--r-- | lib/common/Timer.h | 4 |
3 files changed, 24 insertions, 22 deletions
diff --git a/lib/common/BoxTime.h b/lib/common/BoxTime.h index cc1571cd..dfc40263 100644 --- a/lib/common/BoxTime.h +++ b/lib/common/BoxTime.h @@ -27,6 +27,10 @@ inline box_time_t SecondsToBoxTime(time_t Seconds) { return ((box_time_t)Seconds * MICRO_SEC_IN_SEC_LL); } +inline uint64_t MilliSecondsToBoxTime(int64_t milliseconds) +{ + return ((box_time_t)milliseconds * 1000); +} inline time_t BoxTimeToSeconds(box_time_t Time) { return Time / MICRO_SEC_IN_SEC_LL; diff --git a/lib/common/Timer.cpp b/lib/common/Timer.cpp index c0451818..81a4dd80 100644 --- a/lib/common/Timer.cpp +++ b/lib/common/Timer.cpp @@ -335,7 +335,7 @@ void Timers::SignalHandler(int unused) // -------------------------------------------------------------------------- // // Function -// Name: Timer::Timer(size_t timeoutSecs, +// Name: Timer::Timer(size_t timeoutMillis, // const std::string& rName) // Purpose: Standard timer constructor, takes a timeout in // seconds from now, and an optional name for @@ -344,8 +344,8 @@ void Timers::SignalHandler(int unused) // // -------------------------------------------------------------------------- -Timer::Timer(size_t timeoutSecs, const std::string& rName) -: mExpires(GetCurrentBoxTime() + SecondsToBoxTime(timeoutSecs)), +Timer::Timer(size_t timeoutMillis, const std::string& rName) +: mExpires(GetCurrentBoxTime() + MilliSecondsToBoxTime(timeoutMillis)), mExpired(false), mName(rName) #ifdef WIN32 @@ -353,26 +353,26 @@ Timer::Timer(size_t timeoutSecs, const std::string& rName) #endif { #ifndef BOX_RELEASE_BUILD - if (timeoutSecs == 0) + if (timeoutMillis == 0) { - BOX_TRACE(TIMER_ID "initialised for " << timeoutSecs << - " secs, will not fire"); + BOX_TRACE(TIMER_ID "initialised for " << timeoutMillis << + " ms, will not fire"); } else { - BOX_TRACE(TIMER_ID "initialised for " << timeoutSecs << - " secs, to fire at " << FormatTime(mExpires, false, true)); + BOX_TRACE(TIMER_ID "initialised for " << timeoutMillis << + " ms, to fire at " << FormatTime(mExpires, false, true)); } #endif - if (timeoutSecs == 0) + if (timeoutMillis == 0) { mExpires = 0; } else { Timers::Add(*this); - Start(timeoutSecs * MICRO_SEC_IN_SEC_LL); + Start(timeoutMillis * 1000); } } @@ -408,7 +408,7 @@ void Timer::Start() // -------------------------------------------------------------------------- // // Function -// Name: Timer::Start(int64_t delayInMicros) +// Name: Timer::Start(int64_t timeoutMillis) // Purpose: This internal function initialises an OS TimerQueue // timer on Windows, with a specified delay already // calculated to save us doing it again. Like @@ -417,23 +417,21 @@ void Timer::Start() // // -------------------------------------------------------------------------- -void Timer::Start(int64_t delayInMicros) +void Timer::Start(int64_t timeoutMillis) { #ifdef WIN32 // only call me once! ASSERT(mTimerHandle == INVALID_HANDLE_VALUE); - int64_t delayInMillis = delayInMicros / 1000; - // Windows XP always seems to fire timers up to 20 ms late, // at least on my test laptop. Not critical in practice, but our // tests are precise enough that they will fail if we don't // correct for it. - delayInMillis -= 20; + timeoutMillis -= 20; // Set a system timer to call our timer routine if (CreateTimerQueueTimer(&mTimerHandle, NULL, TimerRoutine, - (PVOID)this, delayInMillis, 0, WT_EXECUTEINTIMERTHREAD) + (PVOID)this, timeoutMillis, 0, WT_EXECUTEINTIMERTHREAD) == FALSE) { BOX_ERROR(TIMER_ID "failed to create timer: " << @@ -523,8 +521,8 @@ Timer::Timer(const Timer& rToCopy) { BOX_TRACE(TIMER_ID "initialised from timer " << &rToCopy << ", " "to fire at " << - (int)(mExpires / 1000000) << "." << - (int)(mExpires % 1000000)); + (int)(mExpires / MICRO_SEC_IN_SEC_LL) << "." << + (int)(mExpires % MICRO_SEC_IN_SEC_LL)); } #endif @@ -564,8 +562,8 @@ Timer& Timer::operator=(const Timer& rToCopy) { BOX_TRACE(TIMER_ID "initialised from timer " << &rToCopy << ", " "to fire at " << - (int)(rToCopy.mExpires / 1000000) << "." << - (int)(rToCopy.mExpires % 1000000)); + (int)(rToCopy.mExpires / MICRO_SEC_IN_SEC_LL) << "." << + (int)(rToCopy.mExpires % MICRO_SEC_IN_SEC_LL)); } #endif diff --git a/lib/common/Timer.h b/lib/common/Timer.h index 42b2e00f..bd118a18 100644 --- a/lib/common/Timer.h +++ b/lib/common/Timer.h @@ -53,7 +53,7 @@ class Timers class Timer { public: - Timer(size_t timeoutSecs, const std::string& rName = ""); + Timer(size_t timeoutMillis, const std::string& rName = ""); virtual ~Timer(); Timer(const Timer &); Timer &operator=(const Timer &); @@ -74,7 +74,7 @@ private: std::string mName; void Start(); - void Start(int64_t delayInMicros); + void Start(int64_t timeoutMillis); void Stop(); #ifdef WIN32 |