Use the new more efficient .NET 9 Lock type (#18015)

This commit is contained in:
Henrik
2025-01-20 11:41:13 +01:00
committed by GitHub
parent 87916eb9cf
commit ed08923b46
32 changed files with 37 additions and 37 deletions

View File

@@ -12,8 +12,8 @@ namespace Umbraco.Cms.Web.Common.Localization;
public abstract class DynamicRequestCultureProviderBase : RequestCultureProvider
{
private readonly RequestLocalizationOptions _options;
private readonly object _lockerSupportedCultures = new();
private readonly object _lockerSupportedUICultures = new();
private readonly Lock _lockerSupportedCultures = new();
private readonly Lock _lockerSupportedUICultures = new();
/// <summary>
/// Initializes a new instance of the <see cref="DynamicRequestCultureProviderBase" /> class.
@@ -66,7 +66,7 @@ public abstract class DynamicRequestCultureProviderBase : RequestCultureProvider
/// <param name="cultures">The cultures.</param>
/// <param name="locker">The locker object to use.</param>
/// <param name="addAction">The add action to execute.</param>
private static void TryAddLocked(IEnumerable<CultureInfo>? supportedCultures, IEnumerable<StringSegment> cultures, object locker, Action<StringSegment> addAction)
private static void TryAddLocked(IEnumerable<CultureInfo>? supportedCultures, IEnumerable<StringSegment> cultures, Lock locker, Action<StringSegment> addAction)
{
foreach (StringSegment culture in cultures)
{

View File

@@ -11,7 +11,7 @@ namespace Umbraco.Cms.Web.Common.Logging;
/// </remarks>
internal class RegisteredReloadableLogger
{
private static readonly object _frozenLock = new();
private static readonly Lock _frozenLock = new();
private static bool _frozen;
private readonly ReloadableLogger _logger;

View File

@@ -20,7 +20,7 @@ namespace Umbraco.Cms.Web.Common.ModelsBuilder.InMemoryAuto;
internal class CollectibleRuntimeViewCompiler : IViewCompiler
{
private readonly object _cacheLock = new object();
private readonly Lock _cacheLock = new();
private readonly Dictionary<string, CompiledViewDescriptor> _precompiledViews;
private readonly ConcurrentDictionary<string, string> _normalizedPathCache;
private readonly IFileProvider _fileProvider;

View File

@@ -162,7 +162,7 @@ namespace Umbraco.Cms.Web.Common.ModelsBuilder.InMemoryAuto
public Assembly? CurrentModelsAssembly { get; private set; }
/// <inheritdoc />
public object SyncRoot { get; } = new object();
public object SyncRoot { get; } = new();
private UmbracoServices UmbracoServices => _umbracoServices.Value;

View File

@@ -21,7 +21,7 @@ public sealed class RoutableDocumentFilter : IRoutableDocumentFilter
private readonly GlobalSettings _globalSettings;
private readonly IHostingEnvironment _hostingEnvironment;
private readonly ConcurrentDictionary<string, bool> _routeChecks = new(StringComparer.OrdinalIgnoreCase);
private readonly object _routeLocker = new();
private readonly Lock _routeLocker = new();
private readonly WebRoutingSettings _routingSettings;
private object _initLocker = new();
private bool _isInit;

View File

@@ -10,7 +10,7 @@ namespace Umbraco.Cms.Web.Common.Security;
public class BackOfficeSecurity : IBackOfficeSecurity
{
private readonly object _currentUserLock = new();
private readonly Lock _currentUserLock = new();
private readonly IHttpContextAccessor _httpContextAccessor;
private readonly IUserService _userService;
private IUser? _currentUser;