Skip to content

Commit

Permalink
Work around bad linker transform
Browse files Browse the repository at this point in the history
  • Loading branch information
stephentoub committed Jul 31, 2021
1 parent de909a1 commit 4ea83d2
Showing 1 changed file with 18 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -208,17 +208,11 @@ public bool Trim()
// that we may end up firing a trimming event even if an array wasn't trimmed, and potentially
// trim an array we didn't need to. Both of these should be rare occurrences.

// Under high pressure, release all thread locals.
if (pressure == Utilities.MemoryPressure.High)
{
// Under high pressure, release all thread locals.
if (!log.IsEnabled())
{
foreach (KeyValuePair<ThreadLocalArray[], object?> tlsBuckets in _allTlsBuckets)
{
Array.Clear(tlsBuckets.Key);
}
}
else
#if !MONO // TODO https://github.com/mono/linker/issues/2181: Remove !MONO ifdefs in this method once is fixed
if (log.IsEnabled())
{
foreach (KeyValuePair<ThreadLocalArray[], object?> tlsBuckets in _allTlsBuckets)
{
Expand All @@ -232,6 +226,14 @@ public bool Trim()
}
}
}
else
#endif
{
foreach (KeyValuePair<ThreadLocalArray[], object?> tlsBuckets in _allTlsBuckets)
{
Array.Clear(tlsBuckets.Key);
}
}
}
else
{
Expand Down Expand Up @@ -266,10 +268,14 @@ public bool Trim()
{
// Time noticeably wrapped, or we've surpassed the threshold.
// Clear out the array, and log its being trimmed if desired.
if (Interlocked.Exchange(ref buckets[i].Array, null) is T[] buffer &&
log.IsEnabled())
if (Interlocked.Exchange(ref buckets[i].Array, null) is T[] buffer)
{
log.BufferTrimmed(buffer.GetHashCode(), buffer.Length, Id);
#if !MONO
if (log.IsEnabled())
{
log.BufferTrimmed(buffer.GetHashCode(), buffer.Length, Id);
}
#endif
}
}
}
Expand Down

0 comments on commit 4ea83d2

Please sign in to comment.