Skip to content

Commit

Permalink
Fixes Simulator notifier shutdown
Browse files Browse the repository at this point in the history
Reenables PIDTolerance tests and fixes #103
  • Loading branch information
ThadHouse committed Feb 3, 2016
1 parent f4d60c5 commit 06bbdc1
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 9 deletions.
3 changes: 3 additions & 0 deletions HAL/SimulatorHAL/HALNotifier.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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;
}

}
Expand Down
16 changes: 12 additions & 4 deletions HAL/SimulatorHAL/NotifierAlarm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,6 @@ public void Run()
m_enabled = false;
m_callback?.Invoke((uint)SimHooks.GetFPGATime(), IntPtr.Zero);
}


}

}
Expand Down Expand Up @@ -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();
}
}
Expand Down
10 changes: 5 additions & 5 deletions WPILib.Tests/TestPIDTolerance.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

namespace WPILib.Tests
{
//[TestFixture]
[TestFixture]
public class TestPIDTolerance : TestBase
{
private PIDController pid;
Expand Down Expand Up @@ -47,7 +47,7 @@ public void PidWrite(double value)

private FakeOutput output;

//[SetUp]
[SetUp]
public void SetUp()
{
input = new FakeInput();
Expand All @@ -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);
Expand All @@ -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);
Expand Down

0 comments on commit 06bbdc1

Please sign in to comment.