2 * Copyright (C) 2015 Tim Mayberry <mojofunk@gmail.com>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 #ifndef PBD_WINDOWS_TIMER_UTILS_H
20 #define PBD_WINDOWS_TIMER_UTILS_H
29 * Get the minimum Multimedia Timer resolution as supported by the system
30 * @return true if getting min timer resolution was not successful
32 bool get_min_resolution (uint32_t& timer_resolution_ms);
35 * Set the minimum Multimedia Timer resolution as supported by the system
36 * @return true if setting min timer resolution was successful
38 bool set_min_resolution ();
41 * Set current Multimedia Timer resolution. If the timer resolution has already
42 * been set then reset_resolution() must be called before set_resolution will
44 * @return true if setting the timer value was successful, false if setting the
45 * timer resolution failed or the resolution has already been set.
47 bool set_resolution(uint32_t timer_resolution_ms);
50 * Reset Multimedia Timer resolution. In my testing, if the timer resolution is
51 * set below the default, then resetting the resolution will not reset the
52 * timer resolution back to 15ms. At least it does not reset immediately
53 * even after calling Sleep.
54 * @return true if setting the timer value was successful
56 bool reset_resolution();
58 } // namespace MMTIMERS
63 * Initialize the QPC timer, must be called before QPC::get_microseconds will
64 * return a valid value.
65 * @return true if QPC timer is usable, use check_timer_valid to try to check
71 * @return true if QueryPerformanceCounter is usable as a timer source
72 * This should always return true for systems > XP as those versions of windows
73 * have there own tests to check timer validity and will select an appropriate
74 * timer source. This check is not conclusive and there are probably conditions
75 * under which this check will return true but the timer is not monotonic.
77 bool check_timer_valid ();
80 * @return the value of the performance counter converted to microseconds
82 * If initialize returns true then get_microseconds will always return a
83 * positive value. If QPC is not supported(OS < XP) then -1 is returned but the
84 * MS docs say that this won't occur for systems >= XP.
86 int64_t get_microseconds ();
91 * The highest resolution timer source provided by the system. On Vista and
92 * above this is the value returned by QueryPerformanceCounter(QPC). On XP,
93 * this will QPC if supported or otherwise g_get_monotonic_time will be used.
95 * @return A timer value in microseconds or -1 in the event that the reading
96 * the timer source fails.
98 int64_t get_microseconds ();
102 #endif // PBD_WINDOWS_TIMER_UTILS_H