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

Commit

Permalink
Port dotnet/coreclr#8580 to CoreRT (#2327)
Browse files Browse the repository at this point in the history
  • Loading branch information
jkotas authored Dec 10, 2016
1 parent 5b3d372 commit 24d1272
Showing 1 changed file with 12 additions and 1 deletion.
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

0 comments on commit 24d1272

Please sign in to comment.