Skip to content
Merged
Show file tree
Hide file tree
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
19 changes: 2 additions & 17 deletions src/libraries/Common/src/System/Net/LazyAsyncResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,8 @@ internal class LazyAsyncResult : IAsyncResult
private const int ForceAsyncCount = 50;

// This is to avoid user mistakes when they queue another async op from a callback the completes sync.
[ThreadStatic]
private static ThreadContext? t_threadContext;

private static ThreadContext CurrentThreadContext
{
get
{
ThreadContext? threadContext = t_threadContext;
if (threadContext == null)
{
threadContext = new ThreadContext();
t_threadContext = threadContext;
}

return threadContext;
}
}
[field: ThreadStatic]
private static ThreadContext CurrentThreadContext => field ??= new();

private sealed class ThreadContext
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,8 @@ internal static class ContractNameServices
private const char GenericFormatOpeningBracket = '{';
private const char GenericFormatClosingBracket = '}';

[ThreadStatic]
private static Dictionary<Type, string>? typeIdentityCache;

private static Dictionary<Type, string> TypeIdentityCache
{
get
{
return typeIdentityCache ??= new Dictionary<Type, string>();
}
}
[field: ThreadStatic]
private static Dictionary<Type, string> TypeIdentityCache => field ??= new();

internal static string GetTypeIdentity(Type type)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,8 @@ internal sealed class ImportType
private Func<Export, object>? _castSingleValue;
private readonly bool _isOpenGeneric;

[ThreadStatic]
internal static Dictionary<Type, Func<Export, object>?>? _castSingleValueCache;

private static Dictionary<Type, Func<Export, object>?> CastSingleValueCache
{
get
{
return _castSingleValueCache ??= new Dictionary<Type, Func<Export, object>?>();
}
}
[field: ThreadStatic]
private static Dictionary<Type, Func<Export, object>?> CastSingleValueCache => field ??= new();

public ImportType(Type type, ImportCardinality cardinality)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,10 @@ namespace System.Diagnostics
/// </summary>
internal sealed class RandomNumberGenerator
{
[ThreadStatic] private static RandomNumberGenerator? t_random;

private ulong _s0, _s1, _s2, _s3;

public static RandomNumberGenerator Current => t_random ??= new RandomNumberGenerator();
[field: ThreadStatic]
public static RandomNumberGenerator Current => field ??= new();

public unsafe RandomNumberGenerator()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,14 @@ public static bool AutoFlush
set { }
}

[ThreadStatic]
private static int t_indentLevel;
[field: ThreadStatic]
public static int IndentLevel
{
get => t_indentLevel;
get => field;
set
{
t_indentLevel = value < 0 ? 0 : value;
s_provider.OnIndentLevelChanged(t_indentLevel);
field = value < 0 ? 0 : value;
s_provider.OnIndentLevelChanged(field);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -464,9 +464,8 @@ private static void AssertHeaders(CborReader reader, List<(CoseHeaderLabel, Read
}
}

[ThreadStatic]
private static TestKeyRing? t_threadKeys;
private static TestKeyRing ThreadKeys => (t_threadKeys ??= new TestKeyRing());
[field: ThreadStatic]
private static TestKeyRing ThreadKeys => field ??= new();

internal static ECDsa ES256 => ThreadKeys.ES256;
internal static ECDsa ES384 => ThreadKeys.ES384;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1126,31 +1126,29 @@ internal sealed class ContextData

internal bool _asyncFlow;

[ThreadStatic]
private static ContextData? t_staticData;

internal ContextData(bool asyncFlow)
{
_asyncFlow = asyncFlow;
}

[AllowNull]
[field: ThreadStatic]
internal static ContextData TLSCurrentData
{
get => t_staticData ??= new ContextData(false);
get => field ??= new(false);
set
{
if (value == null && t_staticData != null)
if (value == null && field != null)
{
// set each property to null to retain one TLS ContextData copy.
t_staticData.CurrentScope = null;
t_staticData.CurrentTransaction = null;
t_staticData.DefaultComContextState = DefaultComContextState.Unknown;
t_staticData.WeakDefaultComContext = null;
field.CurrentScope = null;
field.CurrentTransaction = null;
field.DefaultComContextState = DefaultComContextState.Unknown;
field.WeakDefaultComContext = null;
}
else
{
t_staticData = value;
field = value;
}
}
}
Expand Down
Loading