Skip to content

Commit 06bbdc1

Browse files
committed
Fixes Simulator notifier shutdown
Reenables PIDTolerance tests and fixes #103
1 parent f4d60c5 commit 06bbdc1

File tree

3 files changed

+20
-9
lines changed

3 files changed

+20
-9
lines changed

HAL/SimulatorHAL/HALNotifier.cs

+3
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ public static void cleanNotifier(IntPtr notifier_pointer, ref int status)
142142
if (notifier.next != null) notifier.next.prev = notifier.prev;
143143
if (notifiers == notifier) notifiers = notifier.next;
144144
Notifiers.Remove(notifier_pointer.ToInt32());
145+
s_notifierCount--;
145146
}
146147

147148
if (Interlocked.Decrement(ref notifierRefCount) == 0)
@@ -153,6 +154,8 @@ public static void cleanNotifier(IntPtr notifier_pointer, ref int status)
153154
//Clean up alarm and manager
154155
s_alarm.Dispose();
155156
s_alarm = null;
157+
//Reset closest trigger to max value for next time.
158+
closestTrigger = ulong.MaxValue;
156159
}
157160

158161
}

HAL/SimulatorHAL/NotifierAlarm.cs

+12-4
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,6 @@ public void Run()
6262
m_enabled = false;
6363
m_callback?.Invoke((uint)SimHooks.GetFPGATime(), IntPtr.Zero);
6464
}
65-
66-
6765
}
6866

6967
}
@@ -94,8 +92,18 @@ public void WriteTriggerTime(ulong triggerTime)
9492

9593
public void Dispose()
9694
{
97-
m_continue = false;
98-
m_enabled = true;
95+
bool gotLock = false;
96+
try
97+
{
98+
m_lockObject.Enter(ref gotLock);
99+
m_continue = false;
100+
m_enabled = true;
101+
}
102+
finally
103+
{
104+
if (gotLock) m_lockObject.Exit();
105+
}
106+
99107
m_alarmThread.Join();
100108
}
101109
}

WPILib.Tests/TestPIDTolerance.cs

+5-5
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
namespace WPILib.Tests
1010
{
11-
//[TestFixture]
11+
[TestFixture]
1212
public class TestPIDTolerance : TestBase
1313
{
1414
private PIDController pid;
@@ -47,7 +47,7 @@ public void PidWrite(double value)
4747

4848
private FakeOutput output;
4949

50-
//[SetUp]
50+
[SetUp]
5151
public void SetUp()
5252
{
5353
input = new FakeInput();
@@ -56,14 +56,14 @@ public void SetUp()
5656
pid.SetInputRange(-range/2, range/2);
5757
}
5858

59-
//[TearDown]
59+
[TearDown]
6060
public void TearDown()
6161
{
6262
pid.Dispose();
6363
pid = null;
6464
}
6565

66-
//[Test]
66+
[Test]
6767
public void TestAbsoluteTolerance()
6868
{
6969
pid.SetAbsoluteTolerance(tolerance);
@@ -79,7 +79,7 @@ public void TestAbsoluteTolerance()
7979
Assert.That(pid.OnTarget(), Is.False, $"Error was in tolerance when it should not have been. Error was {pid.GetAvgError()}");
8080
}
8181

82-
//[Test]
82+
[Test]
8383
public void TestPercentTolerance()
8484
{
8585
pid.SetPercentTolerance(tolerance);

0 commit comments

Comments
 (0)