Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -524,6 +524,7 @@ internal CancellationTokenRegistration InternalRegister(
{
// Assign the next available unique ID.
id = partition.NextAvailableId++;
Debug.Assert(id != 0, "IDs should never be the reserved value 0.");

// Get a node, from the free list if possible or else a new one.
node = partition.FreeNodeList;
Expand Down Expand Up @@ -942,9 +943,16 @@ public CallbackPartition(CancellationTokenSource source)

internal bool Unregister(long id, CallbackNode node)
{
Debug.Assert(id != 0, "Expected non-zero id");
Debug.Assert(node != null, "Expected non-null node");

if (id == 0)
{
// In general, we won't get 0 passed in here. However, race conditions between threads
// Unregistering and also zero'ing out the CancellationTokenRegistration could cause 0
// to be passed in here, in which case there's nothing to do. 0 is never a valid id.
return false;
}

bool lockTaken = false;
Lock.Enter(ref lockTaken);
try
Expand Down