From eb64ea9fc7131f26d4da8bbb6509dcb933def443 Mon Sep 17 00:00:00 2001 From: Peter Johnson Date: Sat, 28 Jul 2018 03:04:41 -0700 Subject: [PATCH] MotorSafetyHelper: Use SmallPtrSet instead of std::set --- .../src/main/native/cpp/MotorSafetyHelper.cpp | 17 +++++++++-------- .../main/native/include/frc/MotorSafetyHelper.h | 8 -------- 2 files changed, 9 insertions(+), 16 deletions(-) diff --git a/wpilibc/src/main/native/cpp/MotorSafetyHelper.cpp b/wpilibc/src/main/native/cpp/MotorSafetyHelper.cpp index 8e892bd95f..e2f0351aa6 100644 --- a/wpilibc/src/main/native/cpp/MotorSafetyHelper.cpp +++ b/wpilibc/src/main/native/cpp/MotorSafetyHelper.cpp @@ -7,6 +7,7 @@ #include "frc/MotorSafetyHelper.h" +#include #include #include @@ -17,8 +18,8 @@ using namespace frc; -std::set MotorSafetyHelper::m_helperList; -wpi::mutex MotorSafetyHelper::m_listMutex; +static wpi::SmallPtrSet 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 lock(m_listMutex); - m_helperList.insert(this); + std::lock_guard lock(listMutex); + helperList.insert(this); } MotorSafetyHelper::~MotorSafetyHelper() { - std::lock_guard lock(m_listMutex); - m_helperList.erase(this); + std::lock_guard lock(listMutex); + helperList.erase(this); } void MotorSafetyHelper::Feed() { @@ -89,8 +90,8 @@ bool MotorSafetyHelper::IsSafetyEnabled() const { } void MotorSafetyHelper::CheckMotors() { - std::lock_guard lock(m_listMutex); - for (auto elem : m_helperList) { + std::lock_guard lock(listMutex); + for (auto elem : helperList) { elem->Check(); } } diff --git a/wpilibc/src/main/native/include/frc/MotorSafetyHelper.h b/wpilibc/src/main/native/include/frc/MotorSafetyHelper.h index eb53917a37..8fbe91ba79 100644 --- a/wpilibc/src/main/native/include/frc/MotorSafetyHelper.h +++ b/wpilibc/src/main/native/include/frc/MotorSafetyHelper.h @@ -7,8 +7,6 @@ #pragma once -#include - #include #include "frc/ErrorBase.h" @@ -114,12 +112,6 @@ class MotorSafetyHelper : public ErrorBase { // The object that is using the helper MotorSafety* m_safeObject; - - // List of all existing MotorSafetyHelper objects. - static std::set m_helperList; - - // Protect accesses to the list of helpers - static wpi::mutex m_listMutex; }; } // namespace frc