13
0

add PBD::WaitTimerRAII with reverse semantics from PBD::TimerRAII

This commit is contained in:
Paul Davis 2021-06-26 11:03:33 -06:00
parent 83b9ab1bee
commit 995137aeb3

View File

@ -103,6 +103,8 @@ public:
return elapsed;
}
bool started() const { return m_start_val != 0; }
/// @return Elapsed time in microseconds
uint64_t elapsed () const {
return m_last_val - m_start_val;
@ -219,6 +221,10 @@ private:
int _queue_reset;
};
/** Provides an exception (and return path)-safe method to measure a timer
* interval. The timer is started at scope entry, and updated at scope exit
* (however that occurs)
*/
class LIBPBD_API TimerRAII
{
public:
@ -227,6 +233,20 @@ class LIBPBD_API TimerRAII
TimingStats& stats;
};
/** Reverse semantics from TimerRAII. This starts the timer at scope exit,
* and then updates it (computes interval) at scope entry. This is designed
* for use with a callback API like CoreAudio, where we want to time the
* interval between us being done with our work, and when our callback is
* next executed.
*/
class LIBPBD_API WaitTimerRAII
{
public:
WaitTimerRAII (TimingStats& ts) : stats (ts) { if (stats.started()) { stats.update(); } }
~WaitTimerRAII() { stats.start(); }
TimingStats& stats;
};
class LIBPBD_API TimingData
{
public: