diff options
Diffstat (limited to 'base/time/time.h')
-rw-r--r-- | base/time/time.h | 29 |
1 files changed, 28 insertions, 1 deletions
diff --git a/base/time/time.h b/base/time/time.h index e0435d0..8da08ff 100644 --- a/base/time/time.h +++ b/base/time/time.h @@ -79,6 +79,8 @@ // For FILETIME in FromFileTime, until it moves to a new converter class. // See TODO(iyengar) below. #include <windows.h> + +#include "base/gtest_prod_util.h" #endif #include <limits> @@ -733,16 +735,28 @@ class BASE_EXPORT ThreadTicks : public time_internal::TimeBase<ThreadTicks> { #if (defined(_POSIX_THREAD_CPUTIME) && (_POSIX_THREAD_CPUTIME >= 0)) || \ (defined(OS_MACOSX) && !defined(OS_IOS)) || defined(OS_ANDROID) return true; +#elif defined(OS_WIN) + return IsSupportedWin(); #else return false; #endif } + // Waits until the initialization is completed. Needs to be guarded with a + // call to IsSupported(). + static void WaitUntilInitialized() { +#if defined(OS_WIN) + WaitUntilInitializedWin(); +#endif + } + // Returns thread-specific CPU-time on systems that support this feature. // Needs to be guarded with a call to IsSupported(). Use this timer // to (approximately) measure how much time the calling thread spent doing // actual work vs. being de-scheduled. May return bogus results if the thread - // migrates to another CPU between two calls. + // migrates to another CPU between two calls. Returns an empty ThreadTicks + // object until the initialization is completed. If a clock reading is + // absolutely needed, call WaitUntilInitialized() before this method. static ThreadTicks Now(); private: @@ -752,6 +766,19 @@ class BASE_EXPORT ThreadTicks : public time_internal::TimeBase<ThreadTicks> { // and testing. explicit ThreadTicks(int64 us) : TimeBase(us) { } + +#if defined(OS_WIN) + FRIEND_TEST_ALL_PREFIXES(TimeTicks, TSCTicksPerSecond); + + // Returns the frequency of the TSC in ticks per second, or 0 if it hasn't + // been measured yet. Needs to be guarded with a call to IsSupported(). + // This method is declared here rather than in the anonymous namespace to + // allow testing. + static double TSCTicksPerSecond(); + + static bool IsSupportedWin(); + static void WaitUntilInitializedWin(); +#endif }; // For logging use only. |