Skip to content
This repository has been archived by the owner on Nov 1, 2020. It is now read-only.

Port https://github.com/dotnet/coreclr/pull/8580 to CoreRT #2327

Merged
merged 1 commit into from
Dec 10, 2016
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 @@ -421,12 +421,18 @@ internal bool Remove(TKey key)
int entryIndex = FindEntry(key, out value);
if (entryIndex != -1)
{
ref Entry entry = ref _entries[entryIndex];

//
// We do not free the handle here, as we may be racing with readers who already saw the hash code.
// Instead, we simply overwrite the entry's hash code, so subsequent reads will ignore it.
// The handle will be free'd in Container's finalizer, after the table is resized or discarded.
//
Volatile.Write(ref _entries[entryIndex].hashCode, -1);
Volatile.Write(ref entry.hashCode, -1);

// Also, clear the key to allow GC to collect objects pointed to by the entry
entry.depHnd.SetPrimary(null);

return true;
}
return false;
Expand Down Expand Up @@ -757,6 +763,11 @@ public object GetPrimaryAndSecondary(out Object secondary)
return RuntimeImports.RhHandleGetDependent(_handle, out secondary);
}

public void SetPrimary(Object primary)
{
RuntimeImports.RhHandleSet(_handle, primary);
}

//----------------------------------------------------------------------
// Forces dependentHandle back to non-allocated state (if not already there)
// and frees the handle if needed.
Expand Down