MotorSafetyHelper: Use SmallPtrSet instead of std::set

This commit is contained in:
Peter Johnson
2018-07-28 03:04:41 -07:00
parent 826ed7fe3c
commit eb64ea9fc7
2 changed files with 9 additions and 16 deletions

View File

@@ -7,6 +7,7 @@
#include "frc/MotorSafetyHelper.h"
#include <wpi/SmallPtrSet.h>
#include <wpi/SmallString.h>
#include <wpi/raw_ostream.h>
@@ -17,8 +18,8 @@
using namespace frc;
std::set<MotorSafetyHelper*> MotorSafetyHelper::m_helperList;
wpi::mutex MotorSafetyHelper::m_listMutex;
static wpi::SmallPtrSet<MotorSafetyHelper*, 32> helperList;
static wpi::mutex listMutex;
MotorSafetyHelper::MotorSafetyHelper(MotorSafety* safeObject)
: m_safeObject(safeObject) {
@@ -26,13 +27,13 @@ MotorSafetyHelper::MotorSafetyHelper(MotorSafety* safeObject)
m_expiration = DEFAULT_SAFETY_EXPIRATION;
m_stopTime = Timer::GetFPGATimestamp();
std::lock_guard<wpi::mutex> lock(m_listMutex);
m_helperList.insert(this);
std::lock_guard<wpi::mutex> lock(listMutex);
helperList.insert(this);
}
MotorSafetyHelper::~MotorSafetyHelper() {
std::lock_guard<wpi::mutex> lock(m_listMutex);
m_helperList.erase(this);
std::lock_guard<wpi::mutex> lock(listMutex);
helperList.erase(this);
}
void MotorSafetyHelper::Feed() {
@@ -89,8 +90,8 @@ bool MotorSafetyHelper::IsSafetyEnabled() const {
}
void MotorSafetyHelper::CheckMotors() {
std::lock_guard<wpi::mutex> lock(m_listMutex);
for (auto elem : m_helperList) {
std::lock_guard<wpi::mutex> lock(listMutex);
for (auto elem : helperList) {
elem->Check();
}
}