From 06bbdc115474d8d6e5ac10c4d6233bc559d750d9 Mon Sep 17 00:00:00 2001 From: Thad House Date: Tue, 2 Feb 2016 16:46:58 -0800 Subject: [PATCH] Fixes Simulator notifier shutdown Reenables PIDTolerance tests and fixes #103 --- HAL/SimulatorHAL/HALNotifier.cs | 3 +++ HAL/SimulatorHAL/NotifierAlarm.cs | 16 ++++++++++++---- WPILib.Tests/TestPIDTolerance.cs | 10 +++++----- 3 files changed, 20 insertions(+), 9 deletions(-) diff --git a/HAL/SimulatorHAL/HALNotifier.cs b/HAL/SimulatorHAL/HALNotifier.cs index ec7a060a..601723d8 100644 --- a/HAL/SimulatorHAL/HALNotifier.cs +++ b/HAL/SimulatorHAL/HALNotifier.cs @@ -142,6 +142,7 @@ public static void cleanNotifier(IntPtr notifier_pointer, ref int status) if (notifier.next != null) notifier.next.prev = notifier.prev; if (notifiers == notifier) notifiers = notifier.next; Notifiers.Remove(notifier_pointer.ToInt32()); + s_notifierCount--; } if (Interlocked.Decrement(ref notifierRefCount) == 0) @@ -153,6 +154,8 @@ public static void cleanNotifier(IntPtr notifier_pointer, ref int status) //Clean up alarm and manager s_alarm.Dispose(); s_alarm = null; + //Reset closest trigger to max value for next time. + closestTrigger = ulong.MaxValue; } } diff --git a/HAL/SimulatorHAL/NotifierAlarm.cs b/HAL/SimulatorHAL/NotifierAlarm.cs index 95a6666e..32f2dcc4 100644 --- a/HAL/SimulatorHAL/NotifierAlarm.cs +++ b/HAL/SimulatorHAL/NotifierAlarm.cs @@ -62,8 +62,6 @@ public void Run() m_enabled = false; m_callback?.Invoke((uint)SimHooks.GetFPGATime(), IntPtr.Zero); } - - } } @@ -94,8 +92,18 @@ public void WriteTriggerTime(ulong triggerTime) public void Dispose() { - m_continue = false; - m_enabled = true; + bool gotLock = false; + try + { + m_lockObject.Enter(ref gotLock); + m_continue = false; + m_enabled = true; + } + finally + { + if (gotLock) m_lockObject.Exit(); + } + m_alarmThread.Join(); } } diff --git a/WPILib.Tests/TestPIDTolerance.cs b/WPILib.Tests/TestPIDTolerance.cs index 0a07130b..dc36513f 100644 --- a/WPILib.Tests/TestPIDTolerance.cs +++ b/WPILib.Tests/TestPIDTolerance.cs @@ -8,7 +8,7 @@ namespace WPILib.Tests { - //[TestFixture] + [TestFixture] public class TestPIDTolerance : TestBase { private PIDController pid; @@ -47,7 +47,7 @@ public void PidWrite(double value) private FakeOutput output; - //[SetUp] + [SetUp] public void SetUp() { input = new FakeInput(); @@ -56,14 +56,14 @@ public void SetUp() pid.SetInputRange(-range/2, range/2); } - //[TearDown] + [TearDown] public void TearDown() { pid.Dispose(); pid = null; } - //[Test] + [Test] public void TestAbsoluteTolerance() { pid.SetAbsoluteTolerance(tolerance); @@ -79,7 +79,7 @@ public void TestAbsoluteTolerance() Assert.That(pid.OnTarget(), Is.False, $"Error was in tolerance when it should not have been. Error was {pid.GetAvgError()}"); } - //[Test] + [Test] public void TestPercentTolerance() { pid.SetPercentTolerance(tolerance);