Name the states of a fair-queue entry's cancellation registration

Review feedback on #4782.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Roman Ettlinger
2026-10-14 08:19:51 +02:00
parent e318739143
commit 2d720ec8e0
@@ -1001,12 +1001,13 @@ namespace Opc.Ua
/// </summary>
public void Dispose()
{
int prior = Interlocked.Exchange(ref m_registrationState, kDisposed);
if (prior == kDisposed)
var prior = (RegistrationState)Interlocked.Exchange(
ref m_registrationState, (int)RegistrationState.Disposed);
if (prior == RegistrationState.Disposed)
{
return;
}
if (prior == kRegistered)
if (prior == RegistrationState.Registered)
{
m_registration.Dispose();
}
@@ -1042,7 +1043,10 @@ namespace Opc.Ua
// published unless the entry was disposed meanwhile, possibly by the
// callback running inside Register; the registration is ours to end then.
if (Interlocked.CompareExchange(ref m_registrationState, kRegistered, kNone) != kNone)
if (Interlocked.CompareExchange(
ref m_registrationState,
(int)RegistrationState.Registered,
(int)RegistrationState.None) != (int)RegistrationState.None)
{
registration.Dispose();
}
@@ -1085,15 +1089,31 @@ namespace Opc.Ua
private CancellationTokenRegistration m_registration;
/// <summary>
/// <see cref="kNone"/>, <see cref="kRegistered"/> once the registration is
/// published, or <see cref="kDisposed"/> once disposal started. Changed with
/// <see cref="Interlocked"/>, so that an entry needs no lock object.
/// A <see cref="RegistrationState"/>, stored as an <see cref="int"/> so that
/// <see cref="Interlocked"/> can change it; an entry needs no lock object.
/// </summary>
private int m_registrationState;
private const int kNone = 0;
private const int kRegistered = 1;
private const int kDisposed = 2;
/// <summary>
/// Who owns the cancellation registration of an entry.
/// </summary>
private enum RegistrationState
{
/// <summary>
/// Not registered yet.
/// </summary>
None,
/// <summary>
/// Registered; disposal ends the registration.
/// </summary>
Registered,
/// <summary>
/// Disposal started; a registration made afterwards is ended by its maker.
/// </summary>
Disposed
}
}
/// <summary>