Fix some move constructors (#1754)

Timer didn't have working move semantics because mutexes aren't
moveable, meaning the default implementations were ill-formed.
MotorSafety wasn't locking its mutex.
This commit is contained in:
Tyler Veness
2019-07-07 19:15:59 -07:00
committed by Peter Johnson
parent 8757bc471b
commit e582518bae
3 changed files with 19 additions and 2 deletions

View File

@@ -39,6 +39,21 @@ const double Timer::kRolloverTime = (1ll << 32) / 1e6;
Timer::Timer() { Reset(); }
Timer::Timer(Timer&& rhs)
: m_startTime(std::move(rhs.m_startTime)),
m_accumulatedTime(std::move(rhs.m_accumulatedTime)),
m_running(std::move(rhs.m_running)) {}
Timer& Timer::operator=(Timer&& rhs) {
std::scoped_lock lock(m_mutex, rhs.m_mutex);
m_startTime = std::move(rhs.m_startTime);
m_accumulatedTime = std::move(rhs.m_accumulatedTime);
m_running = std::move(rhs.m_running);
return *this;
}
double Timer::Get() const {
double result;
double currentTime = GetFPGATimestamp();