mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-19 00:41:43 +00:00
[hal] Add more shutdown checks and motor safety shutdown (#4510)
This commit is contained in:
@@ -49,8 +49,6 @@ void Thread::Main() {
|
||||
|
||||
HAL_RemoveNewDataEventHandle(event.GetHandle());
|
||||
}
|
||||
|
||||
static wpi::SafeThreadOwner<Thread> m_owner;
|
||||
} // namespace
|
||||
|
||||
static std::atomic_bool gShutdown{false};
|
||||
@@ -59,6 +57,7 @@ namespace {
|
||||
struct MotorSafetyManager {
|
||||
~MotorSafetyManager() { gShutdown = true; }
|
||||
|
||||
wpi::SafeThreadOwner<Thread> thread;
|
||||
wpi::SmallPtrSet<MotorSafety*, 32> instanceList;
|
||||
wpi::mutex listMutex;
|
||||
bool threadStarted = false;
|
||||
@@ -76,6 +75,10 @@ void ResetMotorSafety() {
|
||||
auto& manager = GetManager();
|
||||
std::scoped_lock lock(manager.listMutex);
|
||||
manager.instanceList.clear();
|
||||
manager.thread.Stop();
|
||||
manager.thread.Join();
|
||||
manager.thread = wpi::SafeThreadOwner<Thread>{};
|
||||
manager.threadStarted = false;
|
||||
}
|
||||
} // namespace frc::impl
|
||||
#endif
|
||||
@@ -86,7 +89,7 @@ MotorSafety::MotorSafety() {
|
||||
manager.instanceList.insert(this);
|
||||
if (!manager.threadStarted) {
|
||||
manager.threadStarted = true;
|
||||
m_owner.Start();
|
||||
manager.thread.Start();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user