summaryrefslogtreecommitdiff
path: root/libs/pbd/windows_timer_utils.cc
diff options
context:
space:
mode:
authorTim Mayberry <mojofunk@gmail.com>2015-09-14 11:19:17 +1000
committerTim Mayberry <mojofunk@gmail.com>2015-09-16 11:22:16 +1000
commitf4cb4e479da988df8f8d0dcb369e0ba4b358128e (patch)
treee4442f89e29a36fb2ac7650ead054231297d256f /libs/pbd/windows_timer_utils.cc
parentcd05d46c007583a27be23e2ae8cedc5ea9746373 (diff)
Rename PBD::QPC::get_timer_valid to check_timer_valid and perform timer test
I'm not sure if this test is going to be effective as I don't have hardware to test on at the moment. As noted in the documentation, Windows XP should be the only OS where QPC uses a timer source that is non-monotonic(multi-core with non-syncronized TSC).
Diffstat (limited to 'libs/pbd/windows_timer_utils.cc')
-rw-r--r--libs/pbd/windows_timer_utils.cc23
1 files changed, 21 insertions, 2 deletions
diff --git a/libs/pbd/windows_timer_utils.cc b/libs/pbd/windows_timer_utils.cc
index d95a69e0c7..ee7cd962c5 100644
--- a/libs/pbd/windows_timer_utils.cc
+++ b/libs/pbd/windows_timer_utils.cc
@@ -136,16 +136,35 @@ qpc_frequency_cached ()
return frequency;
}
+bool
+test_qpc_validity ()
+{
+ int64_t last_timer_val = PBD::QPC::get_microseconds ();
+ if (last_timer_val < 0) return false;
+
+ for (int i = 0; i < 100000; ++i) {
+ int64_t timer_val = PBD::QPC::get_microseconds ();
+ if (timer_val < 0) return false;
+ // try and test for non-syncronized TSC(AMD K8/etc)
+ if (timer_val < last_timer_val) return false;
+ last_timer_val = timer_val;
+ }
+ return true;
+}
+
} // anon namespace
namespace QPC {
bool
-get_timer_valid ()
+check_timer_valid ()
{
// setup caching the timer frequency
qpc_frequency_cached ();
- return qpc_frequency_success ();
+ if (!qpc_frequency_success ()) {
+ return false;
+ }
+ return test_qpc_validity ();
}
int64_t