1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-10-25 07:43:54 +02:00

Make PlaybackSchedule::mTime atomic and rename some functions...

... The variable ought to be atomic because it is read and written by different
threads.

Use local variables to avoid repeated reads of the atomic.
This commit is contained in:
Paul Licameli
2018-08-10 13:18:13 -04:00
parent 8a78ae280c
commit f036700b09
2 changed files with 98 additions and 45 deletions

View File

@@ -18,6 +18,7 @@
#include "Experimental.h"
#include "MemoryX.h"
#include <atomic>
#include <utility>
#include <vector>
#include <wx/atomic.h>
@@ -832,8 +833,11 @@ private:
double mT0;
/// Playback ends at offset of mT1, which is measured in seconds. Note that mT1 may be less than mT0 during scrubbing.
double mT1;
/// Current time position during playback, in seconds. Between mT0 and mT1.
double mTime;
/// Current track time position during playback, in seconds.
/// Initialized by the main thread but updated by worker threads during
/// playback or recording, and periodically reread by the main thread for
/// purposes such as display update.
std::atomic<double> mTime;
/// Accumulated real time (not track position), starting at zero (unlike
/// mTime), and wrapping back to zero each time around looping play.
@@ -877,19 +881,38 @@ private:
return mT1 < mT0;
}
/** \brief Get current track time value, unadjusted
*
* Returns a time in seconds.
*/
double GetTrackTime() const
{ return mTime.load(std::memory_order_relaxed); }
/** \brief Set current track time value, unadjusted
*/
void SetTrackTime( double time )
{ mTime.store(time, std::memory_order_relaxed); }
/** \brief Clamps argument to be between mT0 and mT1
*
* Returns the bound if the value is out of bounds; does not wrap.
* Returns a time in seconds.
*/
double ClampTrackTime( double trackTime ) const;
/** \brief Clamps mTime to be between mT0 and mT1
*
* Returns the bound if the value is out of bounds; does not wrap.
* Returns a time in seconds.
*/
double LimitStreamTime() const;
double LimitTrackTime() const;
/** \brief Normalizes mTime, clamping it and handling gaps from cut preview.
*
* Clamps the time (unless scrubbing), and skips over the cut section.
* Returns a time in seconds.
*/
double NormalizeStreamTime() const;
double NormalizeTrackTime() const;
void ResetMode() { mPlayMode = PLAY_STRAIGHT; }
@@ -903,6 +926,9 @@ private:
// is completed at the current value of mTime
bool PassIsComplete() const;
// Returns true if time equals t1 or is on opposite side of t1, to t0
bool Overruns( double trackTime ) const;
void TrackTimeUpdate(double realElapsed);
// Convert a nonnegative real duration to an increment of track time
@@ -921,7 +947,7 @@ private:
// Determine starting duration within the first pass -- sometimes not
// zero
void RealTimeInit();
void RealTimeInit( double trackTime );
void RealTimeRestart();