13
0

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).
This commit is contained in:
Tim Mayberry 2015-09-14 11:19:17 +10:00
parent cd05d46c00
commit f4cb4e479d
3 changed files with 27 additions and 4 deletions

View File

@ -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

View File

@ -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);

View File

@ -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