| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 // Time represents an absolute point in coordinated universal time (UTC), | 5 // Time represents an absolute point in coordinated universal time (UTC), |
| 6 // internally represented as microseconds (s/1,000,000) since the Windows epoch | 6 // internally represented as microseconds (s/1,000,000) since the Windows epoch |
| 7 // (1601-01-01 00:00:00 UTC). System-dependent clock interface routines are | 7 // (1601-01-01 00:00:00 UTC). System-dependent clock interface routines are |
| 8 // defined in time_PLATFORM.cc. Note that values for Time may skew and jump | 8 // defined in time_PLATFORM.cc. Note that values for Time may skew and jump |
| 9 // around as the operating system makes adjustments to synchronize (e.g., with | 9 // around as the operating system makes adjustments to synchronize (e.g., with |
| 10 // NTP servers). Thus, client code that uses the Time class must account for | 10 // NTP servers). Thus, client code that uses the Time class must account for |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 67 | 67 |
| 68 #if defined(OS_POSIX) | 68 #if defined(OS_POSIX) |
| 69 #include <unistd.h> | 69 #include <unistd.h> |
| 70 #include <sys/time.h> | 70 #include <sys/time.h> |
| 71 #endif | 71 #endif |
| 72 | 72 |
| 73 #if defined(OS_WIN) | 73 #if defined(OS_WIN) |
| 74 // For FILETIME in FromFileTime, until it moves to a new converter class. | 74 // For FILETIME in FromFileTime, until it moves to a new converter class. |
| 75 // See TODO(iyengar) below. | 75 // See TODO(iyengar) below. |
| 76 #include <windows.h> | 76 #include <windows.h> |
| 77 | |
| 78 #include "base/gtest_prod_util.h" | 77 #include "base/gtest_prod_util.h" |
| 79 #endif | 78 #endif |
| 80 | 79 |
| 81 namespace base { | 80 namespace base { |
| 82 | 81 |
| 82 class PlatformThreadHandle; |
| 83 class TimeDelta; | 83 class TimeDelta; |
| 84 | 84 |
| 85 // The functions in the time_internal namespace are meant to be used only by the | 85 // The functions in the time_internal namespace are meant to be used only by the |
| 86 // time classes and functions. Please use the math operators defined in the | 86 // time classes and functions. Please use the math operators defined in the |
| 87 // time classes instead. | 87 // time classes instead. |
| 88 namespace time_internal { | 88 namespace time_internal { |
| 89 | 89 |
| 90 // Add or subtract |value| from a TimeDelta. The int64_t argument and return | 90 // Add or subtract |value| from a TimeDelta. The int64_t argument and return |
| 91 // value are in terms of a microsecond timebase. | 91 // value are in terms of a microsecond timebase. |
| 92 BASE_EXPORT int64_t SaturatedAdd(TimeDelta delta, int64_t value); | 92 BASE_EXPORT int64_t SaturatedAdd(TimeDelta delta, int64_t value); |
| (...skipping 649 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 742 | 742 |
| 743 // Returns thread-specific CPU-time on systems that support this feature. | 743 // Returns thread-specific CPU-time on systems that support this feature. |
| 744 // Needs to be guarded with a call to IsSupported(). Use this timer | 744 // Needs to be guarded with a call to IsSupported(). Use this timer |
| 745 // to (approximately) measure how much time the calling thread spent doing | 745 // to (approximately) measure how much time the calling thread spent doing |
| 746 // actual work vs. being de-scheduled. May return bogus results if the thread | 746 // actual work vs. being de-scheduled. May return bogus results if the thread |
| 747 // migrates to another CPU between two calls. Returns an empty ThreadTicks | 747 // migrates to another CPU between two calls. Returns an empty ThreadTicks |
| 748 // object until the initialization is completed. If a clock reading is | 748 // object until the initialization is completed. If a clock reading is |
| 749 // absolutely needed, call WaitUntilInitialized() before this method. | 749 // absolutely needed, call WaitUntilInitialized() before this method. |
| 750 static ThreadTicks Now(); | 750 static ThreadTicks Now(); |
| 751 | 751 |
| 752 #if defined(OS_WIN) |
| 753 // Similar to Now() above except this returns thread-specific CPU time for an |
| 754 // arbitrary thread. All comments for Now() method above apply apply to this |
| 755 // method as well. |
| 756 static ThreadTicks GetForThread(const PlatformThreadHandle& thread_handle); |
| 757 #endif |
| 758 |
| 752 private: | 759 private: |
| 753 friend class time_internal::TimeBase<ThreadTicks>; | 760 friend class time_internal::TimeBase<ThreadTicks>; |
| 754 | 761 |
| 755 // Please use Now() to create a new object. This is for internal use | 762 // Please use Now() or GetForThread() to create a new object. This is for |
| 756 // and testing. | 763 // internal use and testing. |
| 757 explicit ThreadTicks(int64_t us) : TimeBase(us) {} | 764 explicit ThreadTicks(int64_t us) : TimeBase(us) {} |
| 758 | 765 |
| 759 #if defined(OS_WIN) | 766 #if defined(OS_WIN) |
| 760 FRIEND_TEST_ALL_PREFIXES(TimeTicks, TSCTicksPerSecond); | 767 FRIEND_TEST_ALL_PREFIXES(TimeTicks, TSCTicksPerSecond); |
| 761 | 768 |
| 762 // Returns the frequency of the TSC in ticks per second, or 0 if it hasn't | 769 // Returns the frequency of the TSC in ticks per second, or 0 if it hasn't |
| 763 // been measured yet. Needs to be guarded with a call to IsSupported(). | 770 // been measured yet. Needs to be guarded with a call to IsSupported(). |
| 764 // This method is declared here rather than in the anonymous namespace to | 771 // This method is declared here rather than in the anonymous namespace to |
| 765 // allow testing. | 772 // allow testing. |
| 766 static double TSCTicksPerSecond(); | 773 static double TSCTicksPerSecond(); |
| 767 | 774 |
| 768 static bool IsSupportedWin(); | 775 static bool IsSupportedWin(); |
| 769 static void WaitUntilInitializedWin(); | 776 static void WaitUntilInitializedWin(); |
| 770 #endif | 777 #endif |
| 771 }; | 778 }; |
| 772 | 779 |
| 773 // For logging use only. | 780 // For logging use only. |
| 774 BASE_EXPORT std::ostream& operator<<(std::ostream& os, ThreadTicks time_ticks); | 781 BASE_EXPORT std::ostream& operator<<(std::ostream& os, ThreadTicks time_ticks); |
| 775 | 782 |
| 776 } // namespace base | 783 } // namespace base |
| 777 | 784 |
| 778 #endif // BASE_TIME_TIME_H_ | 785 #endif // BASE_TIME_TIME_H_ |
| OLD | NEW |