diff --git a/libs/pbd/pbd.cc b/libs/pbd/pbd.cc index 15b8e1ab1c..d1748cad72 100644 --- a/libs/pbd/pbd.cc +++ b/libs/pbd/pbd.cc @@ -36,6 +36,7 @@ #include "pbd/id.h" #include "pbd/enumwriter.h" #include "pbd/fpu.h" +#include "pbd/microseconds.h" #include "pbd/xml++.h" #ifdef PLATFORM_WINDOWS @@ -80,6 +81,8 @@ PBD::init () return true; } + microsecond_timer_init (); + #ifdef PLATFORM_WINDOWS // Essential!! Make sure that any files used by Ardour // will be created or opened in BINARY mode! diff --git a/libs/pbd/pbd/windows_timer_utils.h b/libs/pbd/pbd/windows_timer_utils.h index d6cb0d1ab5..72c4d19da5 100644 --- a/libs/pbd/pbd/windows_timer_utils.h +++ b/libs/pbd/pbd/windows_timer_utils.h @@ -59,46 +59,6 @@ bool LIBPBD_API reset_resolution(); } // namespace MMTIMERS -namespace QPC { - -/** - * Initialize the QPC timer, must be called before QPC::get_microseconds will - * return a valid value. - * @return true if QPC timer is usable, use check_timer_valid to try to check - * if it is monotonic. - */ -bool LIBPBD_API initialize (); - -/** - * @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. This check is not conclusive and there are probably conditions - * under which this check will return true but the timer is not monotonic. - */ -bool LIBPBD_API check_timer_valid (); - -/** - * @return the value of the performance counter converted to microseconds - * - * If initialize returns true then get_microseconds will always return a - * positive value. If QPC is not supported(OS < XP) then -1 is returned but the - * MS docs say that this won't occur for systems >= XP. - */ -int64_t LIBPBD_API get_microseconds (); - -} // namespace QPC - -/** - * The highest resolution timer source provided by the system. On Vista and - * above this is the value returned by QueryPerformanceCounter(QPC). On XP, - * this will QPC if supported or otherwise g_get_monotonic_time will be used. - * - * @return A timer value in microseconds or -1 in the event that the reading - * the timer source fails. - */ -int64_t LIBPBD_API get_microseconds (); - } // namespace PBD #endif // PBD_WINDOWS_TIMER_UTILS_H diff --git a/libs/pbd/windows_timer_utils.cc b/libs/pbd/windows_timer_utils.cc index 45242427a4..e6d3f8fd9c 100644 --- a/libs/pbd/windows_timer_utils.cc +++ b/libs/pbd/windows_timer_utils.cc @@ -111,81 +111,3 @@ reset_resolution () } // namespace MMTIMERS -namespace { - -static double timer_rate_us = 0.0; - -static -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 -check_timer_valid () -{ - if (!timer_rate_us) { - return false; - } - return test_qpc_validity (); -} - -bool -initialize () -{ - LARGE_INTEGER freq; - if (!QueryPerformanceFrequency(&freq) || freq.QuadPart < 1) { - info << X_("Failed to determine frequency of QPC\n") << endmsg; - timer_rate_us = 0; - } else { - timer_rate_us = 1000000.0 / freq.QuadPart; - } - info << string_compose(X_("QPC timer microseconds per tick: %1\n"), - timer_rate_us) << endmsg; - return !timer_rate_us; -} - -int64_t -get_microseconds () -{ - LARGE_INTEGER current_val; - - if (timer_rate_us) { - // MS docs say this will always succeed for systems >= XP but it may - // not return a monotonic value with non-invariant TSC's etc - if (QueryPerformanceCounter(¤t_val) != 0) { - return (int64_t)(current_val.QuadPart * timer_rate_us); - } - } - DEBUG_TIMING ("Could not get QPC timer\n"); - return -1; -} - -} // namespace QPC - -int64_t -get_microseconds () -{ - if (timer_rate_us) { - return QPC::get_microseconds (); - } - // For XP systems that don't support a high-res performance counter - return g_get_monotonic_time (); -} - -} // namespace PBD diff --git a/libs/pbd/wscript b/libs/pbd/wscript index af5dffa2e6..77b41d6d10 100644 --- a/libs/pbd/wscript +++ b/libs/pbd/wscript @@ -56,6 +56,7 @@ libpbd_sources = [ 'localtime_r.cc', 'malign.cc', 'md5.cc', + 'microseconds.cc', 'mountpoint.cc', 'openuri.cc', 'pathexpand.cc',