mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-24 01:31:46 +00:00
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:
committed by
Peter Johnson
parent
8757bc471b
commit
e582518bae
@@ -39,6 +39,8 @@ MotorSafety::MotorSafety(MotorSafety&& rhs)
|
||||
m_stopTime(std::move(rhs.m_stopTime)) {}
|
||||
|
||||
MotorSafety& MotorSafety::operator=(MotorSafety&& rhs) {
|
||||
std::scoped_lock lock(m_thisMutex, rhs.m_thisMutex);
|
||||
|
||||
ErrorBase::operator=(std::move(rhs));
|
||||
|
||||
m_expiration = std::move(rhs.m_expiration);
|
||||
|
||||
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user