mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-21 01:01:43 +00:00
Cleaned up variable names for std::lock_guard and their associated mutexes (#759)
This commit is contained in:
committed by
Peter Johnson
parent
96de0b5b11
commit
ba879f4663
@@ -40,7 +40,7 @@ void Scheduler::SetEnabled(bool enabled) { m_enabled = enabled; }
|
||||
* @param command The command to be scheduled
|
||||
*/
|
||||
void Scheduler::AddCommand(Command* command) {
|
||||
std::lock_guard<wpi::mutex> sync(m_additionsLock);
|
||||
std::lock_guard<wpi::mutex> lock(m_additionsMutex);
|
||||
if (std::find(m_additions.begin(), m_additions.end(), command) !=
|
||||
m_additions.end())
|
||||
return;
|
||||
@@ -48,7 +48,7 @@ void Scheduler::AddCommand(Command* command) {
|
||||
}
|
||||
|
||||
void Scheduler::AddButton(ButtonScheduler* button) {
|
||||
std::lock_guard<wpi::mutex> sync(m_buttonsLock);
|
||||
std::lock_guard<wpi::mutex> lock(m_buttonsMutex);
|
||||
m_buttons.push_back(button);
|
||||
}
|
||||
|
||||
@@ -114,7 +114,7 @@ void Scheduler::Run() {
|
||||
{
|
||||
if (!m_enabled) return;
|
||||
|
||||
std::lock_guard<wpi::mutex> sync(m_buttonsLock);
|
||||
std::lock_guard<wpi::mutex> lock(m_buttonsMutex);
|
||||
for (auto rButtonIter = m_buttons.rbegin(); rButtonIter != m_buttons.rend();
|
||||
rButtonIter++) {
|
||||
(*rButtonIter)->Execute();
|
||||
@@ -144,7 +144,7 @@ void Scheduler::Run() {
|
||||
|
||||
// Add the new things
|
||||
{
|
||||
std::lock_guard<wpi::mutex> sync(m_additionsLock);
|
||||
std::lock_guard<wpi::mutex> lock(m_additionsMutex);
|
||||
for (auto additionsIter = m_additions.begin();
|
||||
additionsIter != m_additions.end(); additionsIter++) {
|
||||
ProcessCommandAddition(*additionsIter);
|
||||
|
||||
@@ -26,7 +26,7 @@ std::array<bool, 3> DigitalGlitchFilter::m_filterAllocated = {
|
||||
wpi::mutex DigitalGlitchFilter::m_mutex;
|
||||
|
||||
DigitalGlitchFilter::DigitalGlitchFilter() {
|
||||
std::lock_guard<wpi::mutex> sync(m_mutex);
|
||||
std::lock_guard<wpi::mutex> lock(m_mutex);
|
||||
auto index =
|
||||
std::find(m_filterAllocated.begin(), m_filterAllocated.end(), false);
|
||||
wpi_assert(index != m_filterAllocated.end());
|
||||
@@ -39,7 +39,7 @@ DigitalGlitchFilter::DigitalGlitchFilter() {
|
||||
|
||||
DigitalGlitchFilter::~DigitalGlitchFilter() {
|
||||
if (m_channelIndex >= 0) {
|
||||
std::lock_guard<wpi::mutex> sync(m_mutex);
|
||||
std::lock_guard<wpi::mutex> lock(m_mutex);
|
||||
m_filterAllocated[m_channelIndex] = false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -38,12 +38,12 @@ MotorSafetyHelper::MotorSafetyHelper(MotorSafety* safeObject)
|
||||
m_expiration = DEFAULT_SAFETY_EXPIRATION;
|
||||
m_stopTime = Timer::GetFPGATimestamp();
|
||||
|
||||
std::lock_guard<wpi::mutex> sync(m_listMutex);
|
||||
std::lock_guard<wpi::mutex> lock(m_listMutex);
|
||||
m_helperList.insert(this);
|
||||
}
|
||||
|
||||
MotorSafetyHelper::~MotorSafetyHelper() {
|
||||
std::lock_guard<wpi::mutex> sync(m_listMutex);
|
||||
std::lock_guard<wpi::mutex> lock(m_listMutex);
|
||||
m_helperList.erase(this);
|
||||
}
|
||||
|
||||
@@ -53,7 +53,7 @@ MotorSafetyHelper::~MotorSafetyHelper() {
|
||||
* Resets the timer on this object that is used to do the timeouts.
|
||||
*/
|
||||
void MotorSafetyHelper::Feed() {
|
||||
std::lock_guard<wpi::mutex> sync(m_syncMutex);
|
||||
std::lock_guard<wpi::mutex> lock(m_thisMutex);
|
||||
m_stopTime = Timer::GetFPGATimestamp() + m_expiration;
|
||||
}
|
||||
|
||||
@@ -63,7 +63,7 @@ void MotorSafetyHelper::Feed() {
|
||||
* @param expirationTime The timeout value in seconds.
|
||||
*/
|
||||
void MotorSafetyHelper::SetExpiration(double expirationTime) {
|
||||
std::lock_guard<wpi::mutex> sync(m_syncMutex);
|
||||
std::lock_guard<wpi::mutex> lock(m_thisMutex);
|
||||
m_expiration = expirationTime;
|
||||
}
|
||||
|
||||
@@ -73,7 +73,7 @@ void MotorSafetyHelper::SetExpiration(double expirationTime) {
|
||||
* @return the timeout value in seconds.
|
||||
*/
|
||||
double MotorSafetyHelper::GetExpiration() const {
|
||||
std::lock_guard<wpi::mutex> sync(m_syncMutex);
|
||||
std::lock_guard<wpi::mutex> lock(m_thisMutex);
|
||||
return m_expiration;
|
||||
}
|
||||
|
||||
@@ -84,7 +84,7 @@ double MotorSafetyHelper::GetExpiration() const {
|
||||
* timed out.
|
||||
*/
|
||||
bool MotorSafetyHelper::IsAlive() const {
|
||||
std::lock_guard<wpi::mutex> sync(m_syncMutex);
|
||||
std::lock_guard<wpi::mutex> lock(m_thisMutex);
|
||||
return !m_enabled || m_stopTime > Timer::GetFPGATimestamp();
|
||||
}
|
||||
|
||||
@@ -99,7 +99,7 @@ void MotorSafetyHelper::Check() {
|
||||
DriverStation& ds = DriverStation::GetInstance();
|
||||
if (!m_enabled || ds.IsDisabled() || ds.IsTest()) return;
|
||||
|
||||
std::lock_guard<wpi::mutex> sync(m_syncMutex);
|
||||
std::lock_guard<wpi::mutex> lock(m_thisMutex);
|
||||
if (m_stopTime < Timer::GetFPGATimestamp()) {
|
||||
llvm::SmallString<128> buf;
|
||||
llvm::raw_svector_ostream desc(buf);
|
||||
@@ -118,7 +118,7 @@ void MotorSafetyHelper::Check() {
|
||||
* @param enabled True if motor safety is enforced for this object
|
||||
*/
|
||||
void MotorSafetyHelper::SetSafetyEnabled(bool enabled) {
|
||||
std::lock_guard<wpi::mutex> sync(m_syncMutex);
|
||||
std::lock_guard<wpi::mutex> lock(m_thisMutex);
|
||||
m_enabled = enabled;
|
||||
}
|
||||
|
||||
@@ -130,7 +130,7 @@ void MotorSafetyHelper::SetSafetyEnabled(bool enabled) {
|
||||
* @return True if motor safety is enforced for this device
|
||||
*/
|
||||
bool MotorSafetyHelper::IsSafetyEnabled() const {
|
||||
std::lock_guard<wpi::mutex> sync(m_syncMutex);
|
||||
std::lock_guard<wpi::mutex> lock(m_thisMutex);
|
||||
return m_enabled;
|
||||
}
|
||||
|
||||
@@ -141,7 +141,7 @@ bool MotorSafetyHelper::IsSafetyEnabled() const {
|
||||
* that have timed out.
|
||||
*/
|
||||
void MotorSafetyHelper::CheckMotors() {
|
||||
std::lock_guard<wpi::mutex> sync(m_listMutex);
|
||||
std::lock_guard<wpi::mutex> lock(m_listMutex);
|
||||
for (auto elem : m_helperList) {
|
||||
elem->Check();
|
||||
}
|
||||
|
||||
@@ -39,7 +39,7 @@ Notifier::Notifier(TimerEventHandler handler) {
|
||||
|
||||
TimerEventHandler handler;
|
||||
{
|
||||
std::lock_guard<wpi::mutex> sync(m_processMutex);
|
||||
std::lock_guard<wpi::mutex> lock(m_processMutex);
|
||||
handler = m_handler;
|
||||
if (m_periodic) {
|
||||
m_expirationTime += m_period;
|
||||
@@ -88,7 +88,7 @@ void Notifier::UpdateAlarm() {
|
||||
* @param handler Handler
|
||||
*/
|
||||
void Notifier::SetHandler(TimerEventHandler handler) {
|
||||
std::lock_guard<wpi::mutex> sync(m_processMutex);
|
||||
std::lock_guard<wpi::mutex> lock(m_processMutex);
|
||||
m_handler = handler;
|
||||
}
|
||||
|
||||
@@ -100,7 +100,7 @@ void Notifier::SetHandler(TimerEventHandler handler) {
|
||||
* @param delay Seconds to wait before the handler is called.
|
||||
*/
|
||||
void Notifier::StartSingle(double delay) {
|
||||
std::lock_guard<wpi::mutex> sync(m_processMutex);
|
||||
std::lock_guard<wpi::mutex> lock(m_processMutex);
|
||||
m_periodic = false;
|
||||
m_period = delay;
|
||||
m_expirationTime = GetClock() + m_period;
|
||||
@@ -118,7 +118,7 @@ void Notifier::StartSingle(double delay) {
|
||||
* after the call to this method.
|
||||
*/
|
||||
void Notifier::StartPeriodic(double period) {
|
||||
std::lock_guard<wpi::mutex> sync(m_processMutex);
|
||||
std::lock_guard<wpi::mutex> lock(m_processMutex);
|
||||
m_periodic = true;
|
||||
m_period = period;
|
||||
m_expirationTime = GetClock() + m_period;
|
||||
|
||||
@@ -136,7 +136,7 @@ void PIDController::Calculate() {
|
||||
PIDOutput* pidOutput;
|
||||
|
||||
{
|
||||
std::lock_guard<wpi::mutex> sync(m_mutex);
|
||||
std::lock_guard<wpi::mutex> lock(m_mutex);
|
||||
pidInput = m_pidInput;
|
||||
pidOutput = m_pidOutput;
|
||||
enabled = m_enabled;
|
||||
@@ -148,7 +148,7 @@ void PIDController::Calculate() {
|
||||
if (enabled) {
|
||||
double feedForward = CalculateFeedForward();
|
||||
|
||||
std::lock_guard<wpi::mutex> sync(m_mutex);
|
||||
std::lock_guard<wpi::mutex> lock(m_mutex);
|
||||
double input = pidInput->PIDGet();
|
||||
double result;
|
||||
PIDOutput* pidOutput;
|
||||
@@ -219,7 +219,7 @@ double PIDController::CalculateFeedForward() {
|
||||
*/
|
||||
void PIDController::SetPID(double p, double i, double d) {
|
||||
{
|
||||
std::lock_guard<wpi::mutex> sync(m_mutex);
|
||||
std::lock_guard<wpi::mutex> lock(m_mutex);
|
||||
m_P = p;
|
||||
m_I = i;
|
||||
m_D = d;
|
||||
@@ -242,7 +242,7 @@ void PIDController::SetPID(double p, double i, double d) {
|
||||
*/
|
||||
void PIDController::SetPID(double p, double i, double d, double f) {
|
||||
{
|
||||
std::lock_guard<wpi::mutex> sync(m_mutex);
|
||||
std::lock_guard<wpi::mutex> lock(m_mutex);
|
||||
m_P = p;
|
||||
m_I = i;
|
||||
m_D = d;
|
||||
@@ -261,7 +261,7 @@ void PIDController::SetPID(double p, double i, double d, double f) {
|
||||
* @return proportional coefficient
|
||||
*/
|
||||
double PIDController::GetP() const {
|
||||
std::lock_guard<wpi::mutex> sync(m_mutex);
|
||||
std::lock_guard<wpi::mutex> lock(m_mutex);
|
||||
return m_P;
|
||||
}
|
||||
|
||||
@@ -271,7 +271,7 @@ double PIDController::GetP() const {
|
||||
* @return integral coefficient
|
||||
*/
|
||||
double PIDController::GetI() const {
|
||||
std::lock_guard<wpi::mutex> sync(m_mutex);
|
||||
std::lock_guard<wpi::mutex> lock(m_mutex);
|
||||
return m_I;
|
||||
}
|
||||
|
||||
@@ -281,7 +281,7 @@ double PIDController::GetI() const {
|
||||
* @return differential coefficient
|
||||
*/
|
||||
double PIDController::GetD() const {
|
||||
std::lock_guard<wpi::mutex> sync(m_mutex);
|
||||
std::lock_guard<wpi::mutex> lock(m_mutex);
|
||||
return m_D;
|
||||
}
|
||||
|
||||
@@ -291,7 +291,7 @@ double PIDController::GetD() const {
|
||||
* @return Feed forward coefficient
|
||||
*/
|
||||
double PIDController::GetF() const {
|
||||
std::lock_guard<wpi::mutex> sync(m_mutex);
|
||||
std::lock_guard<wpi::mutex> lock(m_mutex);
|
||||
return m_F;
|
||||
}
|
||||
|
||||
@@ -303,7 +303,7 @@ double PIDController::GetF() const {
|
||||
* @return the latest calculated output
|
||||
*/
|
||||
double PIDController::Get() const {
|
||||
std::lock_guard<wpi::mutex> sync(m_mutex);
|
||||
std::lock_guard<wpi::mutex> lock(m_mutex);
|
||||
return m_result;
|
||||
}
|
||||
|
||||
@@ -317,7 +317,7 @@ double PIDController::Get() const {
|
||||
* @param continuous true turns on continuous, false turns off continuous
|
||||
*/
|
||||
void PIDController::SetContinuous(bool continuous) {
|
||||
std::lock_guard<wpi::mutex> sync(m_mutex);
|
||||
std::lock_guard<wpi::mutex> lock(m_mutex);
|
||||
m_continuous = continuous;
|
||||
}
|
||||
|
||||
@@ -329,7 +329,7 @@ void PIDController::SetContinuous(bool continuous) {
|
||||
*/
|
||||
void PIDController::SetInputRange(double minimumInput, double maximumInput) {
|
||||
{
|
||||
std::lock_guard<wpi::mutex> sync(m_mutex);
|
||||
std::lock_guard<wpi::mutex> lock(m_mutex);
|
||||
m_minimumInput = minimumInput;
|
||||
m_maximumInput = maximumInput;
|
||||
}
|
||||
@@ -344,7 +344,7 @@ void PIDController::SetInputRange(double minimumInput, double maximumInput) {
|
||||
* @param maximumOutput the maximum value to write to the output
|
||||
*/
|
||||
void PIDController::SetOutputRange(double minimumOutput, double maximumOutput) {
|
||||
std::lock_guard<wpi::mutex> sync(m_mutex);
|
||||
std::lock_guard<wpi::mutex> lock(m_mutex);
|
||||
m_minimumOutput = minimumOutput;
|
||||
m_maximumOutput = maximumOutput;
|
||||
}
|
||||
@@ -356,7 +356,7 @@ void PIDController::SetOutputRange(double minimumOutput, double maximumOutput) {
|
||||
*/
|
||||
void PIDController::SetSetpoint(double setpoint) {
|
||||
{
|
||||
std::lock_guard<wpi::mutex> sync(m_mutex);
|
||||
std::lock_guard<wpi::mutex> lock(m_mutex);
|
||||
|
||||
if (m_maximumInput > m_minimumInput) {
|
||||
if (setpoint > m_maximumInput)
|
||||
@@ -379,7 +379,7 @@ void PIDController::SetSetpoint(double setpoint) {
|
||||
* @return the current setpoint
|
||||
*/
|
||||
double PIDController::GetSetpoint() const {
|
||||
std::lock_guard<wpi::mutex> sync(m_mutex);
|
||||
std::lock_guard<wpi::mutex> lock(m_mutex);
|
||||
return m_setpoint;
|
||||
}
|
||||
|
||||
@@ -389,7 +389,7 @@ double PIDController::GetSetpoint() const {
|
||||
* @return the change in setpoint over time
|
||||
*/
|
||||
double PIDController::GetDeltaSetpoint() const {
|
||||
std::lock_guard<wpi::mutex> sync(m_mutex);
|
||||
std::lock_guard<wpi::mutex> lock(m_mutex);
|
||||
return (m_setpoint - m_prevSetpoint) / m_setpointTimer.Get();
|
||||
}
|
||||
|
||||
@@ -401,7 +401,7 @@ double PIDController::GetDeltaSetpoint() const {
|
||||
double PIDController::GetError() const {
|
||||
double setpoint = GetSetpoint();
|
||||
{
|
||||
std::lock_guard<wpi::mutex> sync(m_mutex);
|
||||
std::lock_guard<wpi::mutex> lock(m_mutex);
|
||||
return GetContinuousError(setpoint - m_pidInput->PIDGet());
|
||||
}
|
||||
}
|
||||
@@ -438,7 +438,7 @@ PIDSourceType PIDController::GetPIDSourceType() const {
|
||||
* @param percentage error which is tolerable
|
||||
*/
|
||||
void PIDController::SetTolerance(double percent) {
|
||||
std::lock_guard<wpi::mutex> sync(m_mutex);
|
||||
std::lock_guard<wpi::mutex> lock(m_mutex);
|
||||
m_toleranceType = kPercentTolerance;
|
||||
m_tolerance = percent;
|
||||
}
|
||||
@@ -450,7 +450,7 @@ void PIDController::SetTolerance(double percent) {
|
||||
* @param percentage error which is tolerable
|
||||
*/
|
||||
void PIDController::SetAbsoluteTolerance(double absTolerance) {
|
||||
std::lock_guard<wpi::mutex> sync(m_mutex);
|
||||
std::lock_guard<wpi::mutex> lock(m_mutex);
|
||||
m_toleranceType = kAbsoluteTolerance;
|
||||
m_tolerance = absTolerance;
|
||||
}
|
||||
@@ -462,7 +462,7 @@ void PIDController::SetAbsoluteTolerance(double absTolerance) {
|
||||
* @param percentage error which is tolerable
|
||||
*/
|
||||
void PIDController::SetPercentTolerance(double percent) {
|
||||
std::lock_guard<wpi::mutex> sync(m_mutex);
|
||||
std::lock_guard<wpi::mutex> lock(m_mutex);
|
||||
m_toleranceType = kPercentTolerance;
|
||||
m_tolerance = percent;
|
||||
}
|
||||
@@ -478,7 +478,7 @@ void PIDController::SetPercentTolerance(double percent) {
|
||||
* @param bufLength Number of previous cycles to average. Defaults to 1.
|
||||
*/
|
||||
void PIDController::SetToleranceBuffer(int bufLength) {
|
||||
std::lock_guard<wpi::mutex> sync(m_mutex);
|
||||
std::lock_guard<wpi::mutex> lock(m_mutex);
|
||||
|
||||
// Create LinearDigitalFilter with original source as its source argument
|
||||
m_filter = LinearDigitalFilter::MovingAverage(m_origSource, bufLength);
|
||||
@@ -499,7 +499,7 @@ void PIDController::SetToleranceBuffer(int bufLength) {
|
||||
bool PIDController::OnTarget() const {
|
||||
double error = GetError();
|
||||
|
||||
std::lock_guard<wpi::mutex> sync(m_mutex);
|
||||
std::lock_guard<wpi::mutex> lock(m_mutex);
|
||||
switch (m_toleranceType) {
|
||||
case kPercentTolerance:
|
||||
return std::fabs(error) <
|
||||
@@ -520,7 +520,7 @@ bool PIDController::OnTarget() const {
|
||||
*/
|
||||
void PIDController::Enable() {
|
||||
{
|
||||
std::lock_guard<wpi::mutex> sync(m_mutex);
|
||||
std::lock_guard<wpi::mutex> lock(m_mutex);
|
||||
m_enabled = true;
|
||||
}
|
||||
|
||||
@@ -532,7 +532,7 @@ void PIDController::Enable() {
|
||||
*/
|
||||
void PIDController::Disable() {
|
||||
{
|
||||
std::lock_guard<wpi::mutex> sync(m_mutex);
|
||||
std::lock_guard<wpi::mutex> lock(m_mutex);
|
||||
m_pidOutput->PIDWrite(0);
|
||||
m_enabled = false;
|
||||
}
|
||||
@@ -544,7 +544,7 @@ void PIDController::Disable() {
|
||||
* Return true if PIDController is enabled.
|
||||
*/
|
||||
bool PIDController::IsEnabled() const {
|
||||
std::lock_guard<wpi::mutex> sync(m_mutex);
|
||||
std::lock_guard<wpi::mutex> lock(m_mutex);
|
||||
return m_enabled;
|
||||
}
|
||||
|
||||
@@ -554,7 +554,7 @@ bool PIDController::IsEnabled() const {
|
||||
void PIDController::Reset() {
|
||||
Disable();
|
||||
|
||||
std::lock_guard<wpi::mutex> sync(m_mutex);
|
||||
std::lock_guard<wpi::mutex> lock(m_mutex);
|
||||
m_prevError = 0;
|
||||
m_totalError = 0;
|
||||
m_result = 0;
|
||||
@@ -583,7 +583,7 @@ void PIDController::InitTable(std::shared_ptr<nt::NetworkTable> subtable) {
|
||||
m_pListener = m_pEntry.AddListener(
|
||||
[=](const nt::EntryNotification& event) {
|
||||
if (!event.value->IsDouble()) return;
|
||||
std::lock_guard<wpi::mutex> sync(m_mutex);
|
||||
std::lock_guard<wpi::mutex> lock(m_mutex);
|
||||
m_P = event.value->GetDouble();
|
||||
},
|
||||
NT_NOTIFY_NEW | NT_NOTIFY_UPDATE);
|
||||
@@ -591,7 +591,7 @@ void PIDController::InitTable(std::shared_ptr<nt::NetworkTable> subtable) {
|
||||
m_iListener = m_iEntry.AddListener(
|
||||
[=](const nt::EntryNotification& event) {
|
||||
if (!event.value->IsDouble()) return;
|
||||
std::lock_guard<wpi::mutex> sync(m_mutex);
|
||||
std::lock_guard<wpi::mutex> lock(m_mutex);
|
||||
m_I = event.value->GetDouble();
|
||||
},
|
||||
NT_NOTIFY_NEW | NT_NOTIFY_UPDATE);
|
||||
@@ -599,7 +599,7 @@ void PIDController::InitTable(std::shared_ptr<nt::NetworkTable> subtable) {
|
||||
m_dListener = m_dEntry.AddListener(
|
||||
[=](const nt::EntryNotification& event) {
|
||||
if (!event.value->IsDouble()) return;
|
||||
std::lock_guard<wpi::mutex> sync(m_mutex);
|
||||
std::lock_guard<wpi::mutex> lock(m_mutex);
|
||||
m_D = event.value->GetDouble();
|
||||
},
|
||||
NT_NOTIFY_NEW | NT_NOTIFY_UPDATE);
|
||||
@@ -607,7 +607,7 @@ void PIDController::InitTable(std::shared_ptr<nt::NetworkTable> subtable) {
|
||||
m_fListener = m_fEntry.AddListener(
|
||||
[=](const nt::EntryNotification& event) {
|
||||
if (!event.value->IsDouble()) return;
|
||||
std::lock_guard<wpi::mutex> sync(m_mutex);
|
||||
std::lock_guard<wpi::mutex> lock(m_mutex);
|
||||
m_F = event.value->GetDouble();
|
||||
},
|
||||
NT_NOTIFY_NEW | NT_NOTIFY_UPDATE);
|
||||
|
||||
@@ -38,7 +38,7 @@ Resource::Resource(uint32_t elements) {
|
||||
*/
|
||||
void Resource::CreateResourceObject(std::unique_ptr<Resource>& r,
|
||||
uint32_t elements) {
|
||||
std::lock_guard<wpi::mutex> sync(m_createMutex);
|
||||
std::lock_guard<wpi::mutex> lock(m_createMutex);
|
||||
if (!r) {
|
||||
r = std::make_unique<Resource>(elements);
|
||||
}
|
||||
@@ -52,7 +52,7 @@ void Resource::CreateResourceObject(std::unique_ptr<Resource>& r,
|
||||
* allocated.
|
||||
*/
|
||||
uint32_t Resource::Allocate(const std::string& resourceDesc) {
|
||||
std::lock_guard<wpi::mutex> sync(m_allocateMutex);
|
||||
std::lock_guard<wpi::mutex> lock(m_allocateMutex);
|
||||
for (uint32_t i = 0; i < m_isAllocated.size(); i++) {
|
||||
if (!m_isAllocated[i]) {
|
||||
m_isAllocated[i] = true;
|
||||
@@ -70,7 +70,7 @@ uint32_t Resource::Allocate(const std::string& resourceDesc) {
|
||||
* verified unallocated, then returned.
|
||||
*/
|
||||
uint32_t Resource::Allocate(uint32_t index, const std::string& resourceDesc) {
|
||||
std::lock_guard<wpi::mutex> sync(m_allocateMutex);
|
||||
std::lock_guard<wpi::mutex> lock(m_allocateMutex);
|
||||
if (index >= m_isAllocated.size()) {
|
||||
wpi_setWPIErrorWithContext(ChannelIndexOutOfRange, resourceDesc);
|
||||
return std::numeric_limits<uint32_t>::max();
|
||||
@@ -91,7 +91,7 @@ uint32_t Resource::Allocate(uint32_t index, const std::string& resourceDesc) {
|
||||
* be reused somewhere else in the program.
|
||||
*/
|
||||
void Resource::Free(uint32_t index) {
|
||||
std::unique_lock<wpi::mutex> sync(m_allocateMutex);
|
||||
std::unique_lock<wpi::mutex> lock(m_allocateMutex);
|
||||
if (index == std::numeric_limits<uint32_t>::max()) return;
|
||||
if (index >= m_isAllocated.size()) {
|
||||
wpi_setWPIError(NotAllocated);
|
||||
|
||||
@@ -80,7 +80,7 @@ double Timer::Get() const {
|
||||
double result;
|
||||
double currentTime = GetFPGATimestamp();
|
||||
|
||||
std::lock_guard<wpi::mutex> sync(m_mutex);
|
||||
std::lock_guard<wpi::mutex> lock(m_mutex);
|
||||
if (m_running) {
|
||||
// If the current time is before the start time, then the FPGA clock rolled
|
||||
// over. Compensate by adding the ~71 minutes that it takes to roll over to
|
||||
@@ -104,7 +104,7 @@ double Timer::Get() const {
|
||||
* now.
|
||||
*/
|
||||
void Timer::Reset() {
|
||||
std::lock_guard<wpi::mutex> sync(m_mutex);
|
||||
std::lock_guard<wpi::mutex> lock(m_mutex);
|
||||
m_accumulatedTime = 0;
|
||||
m_startTime = GetFPGATimestamp();
|
||||
}
|
||||
@@ -116,7 +116,7 @@ void Timer::Reset() {
|
||||
* relative to the system clock.
|
||||
*/
|
||||
void Timer::Start() {
|
||||
std::lock_guard<wpi::mutex> sync(m_mutex);
|
||||
std::lock_guard<wpi::mutex> lock(m_mutex);
|
||||
if (!m_running) {
|
||||
m_startTime = GetFPGATimestamp();
|
||||
m_running = true;
|
||||
@@ -133,7 +133,7 @@ void Timer::Start() {
|
||||
void Timer::Stop() {
|
||||
double temp = Get();
|
||||
|
||||
std::lock_guard<wpi::mutex> sync(m_mutex);
|
||||
std::lock_guard<wpi::mutex> lock(m_mutex);
|
||||
if (m_running) {
|
||||
m_accumulatedTime = temp;
|
||||
m_running = false;
|
||||
@@ -150,7 +150,7 @@ void Timer::Stop() {
|
||||
*/
|
||||
bool Timer::HasPeriodPassed(double period) {
|
||||
if (Get() > period) {
|
||||
std::lock_guard<wpi::mutex> sync(m_mutex);
|
||||
std::lock_guard<wpi::mutex> lock(m_mutex);
|
||||
// Advance the start time by the period.
|
||||
m_startTime += period;
|
||||
// Don't set it to the current time... we want to avoid drift.
|
||||
|
||||
Reference in New Issue
Block a user