mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-21 01:01:43 +00:00
[wpilibj] Make CallbackStore.close() idempotent (#6666)
This is "strongly recommended" in the javadocs for the AutoCloseable.close().
This commit is contained in:
@@ -69,6 +69,7 @@ public class CallbackStore implements AutoCloseable {
|
||||
private CancelCallbackFunc m_cancelCallback;
|
||||
private CancelCallbackChannelFunc m_cancelCallbackChannel;
|
||||
private CancelCallbackNoIndexFunc m_cancelCallbackNoIndex;
|
||||
private static final int kAlreadyCancelled = -1;
|
||||
private static final int kNormalCancel = 0;
|
||||
private static final int kChannelCancel = 1;
|
||||
private static final int kNoIndexCancel = 2;
|
||||
@@ -78,6 +79,9 @@ public class CallbackStore implements AutoCloseable {
|
||||
@Override
|
||||
public void close() {
|
||||
switch (m_cancelType) {
|
||||
case kAlreadyCancelled:
|
||||
// Already cancelled so do nothing so that close() is idempotent.
|
||||
return;
|
||||
case kNormalCancel:
|
||||
m_cancelCallback.cancel(m_index, m_uid);
|
||||
break;
|
||||
@@ -91,6 +95,6 @@ public class CallbackStore implements AutoCloseable {
|
||||
assert false;
|
||||
break;
|
||||
}
|
||||
m_cancelType = -1;
|
||||
m_cancelType = kAlreadyCancelled;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user