summaryrefslogtreecommitdiff
path: root/libs
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
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')
-rw-r--r--libs/pbd/pbd/windows_timer_utils.h5
-rw-r--r--libs/pbd/test/windows_timer_utils_test.cc3
-rw-r--r--libs/pbd/windows_timer_utils.cc23
3 files changed, 27 insertions, 4 deletions
diff --git a/libs/pbd/pbd/windows_timer_utils.h b/libs/pbd/pbd/windows_timer_utils.h
index 72d3cc5431..4ebeacd6eb 100644
--- a/libs/pbd/pbd/windows_timer_utils.h
+++ b/libs/pbd/pbd/windows_timer_utils.h
@@ -61,8 +61,11 @@ namespace QPC {
/**
* @return true if QueryPerformanceCounter is usable as a timer source
+ * This should always return true for systems > XP as those versions of windows
+ * have there own tests to check timer validity and will select an appropriate
+ * timer source.
*/
-bool get_timer_valid ();
+bool check_timer_valid ();
/**
* @return the value of the performance counter converted to microseconds
diff --git a/libs/pbd/test/windows_timer_utils_test.cc b/libs/pbd/test/windows_timer_utils_test.cc
index fe5e1a24df..1566f37d96 100644
--- a/libs/pbd/test/windows_timer_utils_test.cc
+++ b/libs/pbd/test/windows_timer_utils_test.cc
@@ -13,7 +13,8 @@ CPPUNIT_TEST_SUITE_REGISTRATION (WindowsTimerUtilsTest);
void
WindowsTimerUtilsTest::testQPC ()
{
- CPPUNIT_ASSERT (PBD::QPC::get_timer_valid());
+ // performs basically the same test
+ CPPUNIT_ASSERT (PBD::QPC::check_timer_valid());
int64_t last_timer_val = PBD::QPC::get_microseconds ();
CPPUNIT_ASSERT (last_timer_val >= 0);
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