Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use System.Threading.Lock type #17130

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion src/OrchardCore.Build/OrchardCore.Commons.props
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

<PropertyGroup>
<LangVersion>12.0</LangVersion>
<LangVersion>13.0</LangVersion>
<VersionPrefix>3.0.0</VersionPrefix>
<VersionSuffix>preview</VersionSuffix>
<VersionSuffix Condition="'$(VersionSuffix)'!='' AND '$(BuildNumber)' != ''">$(VersionSuffix)-$(BuildNumber)</VersionSuffix>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
using OrchardCore.Search.Lucene.Model;
using OrchardCore.Search.Lucene.Services;
using Spatial4n.Context;
using Lock = System.Threading.Lock;
using Directory = System.IO.Directory;
using LDirectory = Lucene.Net.Store.Directory;
using LuceneLock = Lucene.Net.Store.Lock;
Expand All @@ -37,7 +38,7 @@ public class LuceneIndexManager : IDisposable
private readonly LuceneIndexSettingsService _luceneIndexSettingsService;
private readonly SpatialContext _ctx;
private readonly GeohashPrefixTree _grid;
private static readonly object _synLock = new();
private static readonly Lock _synLock = new();

public LuceneIndexManager(
IClock clock,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
private readonly IHostEnvironment _environment;
private readonly IEnumerable<IModuleNamesProvider> _moduleNamesProviders;
private Application _application;
private static readonly object _initLock = new();
private static readonly Lock _initLock = new();

Check failure on line 11 in src/OrchardCore/OrchardCore.Abstractions/Modules/ModularApplicationContext.cs

View workflow job for this annotation

GitHub Actions / Build & Test (ubuntu-latest)

The type or namespace name 'Lock' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 11 in src/OrchardCore/OrchardCore.Abstractions/Modules/ModularApplicationContext.cs

View workflow job for this annotation

GitHub Actions / Build & Test (ubuntu-latest)

The type or namespace name 'Lock' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 11 in src/OrchardCore/OrchardCore.Abstractions/Modules/ModularApplicationContext.cs

View workflow job for this annotation

GitHub Actions / Build & Test (windows-latest)

The type or namespace name 'Lock' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 11 in src/OrchardCore/OrchardCore.Abstractions/Modules/ModularApplicationContext.cs

View workflow job for this annotation

GitHub Actions / Build & Test (windows-latest)

The type or namespace name 'Lock' could not be found (are you missing a using directive or an assembly reference?)

public ModularApplicationContext(IHostEnvironment environment, IEnumerable<IModuleNamesProvider> moduleNamesProviders)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
public class ModuleProjectStaticFileProvider : IModuleStaticFileProvider
{
private static Dictionary<string, string> _roots;
private static readonly object _synLock = new();
private static readonly Lock _synLock = new();

Check failure on line 14 in src/OrchardCore/OrchardCore.Abstractions/Modules/ModuleProjectStaticFileProvider.cs

View workflow job for this annotation

GitHub Actions / Build & Test (ubuntu-latest)

The type or namespace name 'Lock' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 14 in src/OrchardCore/OrchardCore.Abstractions/Modules/ModuleProjectStaticFileProvider.cs

View workflow job for this annotation

GitHub Actions / Build & Test (ubuntu-latest)

The type or namespace name 'Lock' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 14 in src/OrchardCore/OrchardCore.Abstractions/Modules/ModuleProjectStaticFileProvider.cs

View workflow job for this annotation

GitHub Actions / Build & Test (windows-latest)

The type or namespace name 'Lock' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 14 in src/OrchardCore/OrchardCore.Abstractions/Modules/ModuleProjectStaticFileProvider.cs

View workflow job for this annotation

GitHub Actions / Build & Test (windows-latest)

The type or namespace name 'Lock' could not be found (are you missing a using directive or an assembly reference?)

public ModuleProjectStaticFileProvider(IApplicationContext applicationContext)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class LiquidViewsFeatureProvider : IApplicationFeatureProvider<ViewsFeatu
public static readonly string DefaultLiquidViewPath = '/' + DefaultLiquidViewName + LiquidViewTemplate.ViewExtension;

private static List<string> _sharedPaths;
private static readonly object _synLock = new();
private static readonly Lock _synLock = new();

public LiquidViewsFeatureProvider(IOptions<TemplateOptions> templateOptions)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace OrchardCore.DisplayManagement.Liquid;
public class ModuleProjectLiquidFileProvider : IFileProvider
{
private static Dictionary<string, string> _paths;
private static readonly object _synLock = new();
private static readonly Lock _synLock = new();

public ModuleProjectLiquidFileProvider(IApplicationContext applicationContext)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public class DefaultShapeTableManager : IShapeTableManager
// create a unique list of these per tenant.
private static readonly ConcurrentDictionary<string, FeatureShapeDescriptor> _shapeDescriptors = new();

private static readonly object _syncLock = new();
private static readonly Lock _syncLock = new();

// Singleton cache to hold a tenant's theme ShapeTable.
private readonly IDictionary<string, ShapeTable> _shapeTableCache;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class ComponentViewLocationExpanderProvider : IViewLocationExpanderProvid
private const string CacheKey = "ModuleComponentViewLocations";
private static List<IExtensionInfo> _modulesWithComponentViews;
private static List<IExtensionInfo> _modulesWithPagesComponentViews;
private static readonly object _synLock = new();
private static readonly Lock _synLock = new();
private static bool _initialized;

private readonly IExtensionManager _extensionManager;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class SharedViewLocationExpanderProvider : IViewLocationExpanderProvider
private const string PageCacheKey = "ModulePageSharedViewLocations";
private static List<IExtensionInfo> _modulesWithPageSharedViews;
private static List<IExtensionInfo> _modulesWithSharedViews;
private static readonly object _synLock = new();
private static readonly Lock _synLock = new();

private readonly IExtensionManager _extensionManager;
private readonly ShellDescriptor _shellDescriptor;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class ModuleProjectRazorFileProvider : IFileProvider
{
private static List<IFileProvider> _pageFileProviders;
private static Dictionary<string, string> _roots;
private static readonly object _synLock = new();
private static readonly Lock _synLock = new();

public ModuleProjectRazorFileProvider(IApplicationContext applicationContext)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace OrchardCore.Mvc;
/// </summary>
public class SharedViewCompilerProvider : IViewCompilerProvider
{
private readonly object _synLock = new();
private readonly Lock _synLock = new();
private static IViewCompiler _compiler;
private readonly IServiceProvider _services;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class ShellFeatureApplicationPart :
ICompilationReferencesProvider
{
private static IEnumerable<string> _referencePaths;
private static readonly object _synLock = new();
private static readonly Lock _synLock = new();
private ShellBlueprint _shellBlueprint;
private IEnumerable<ITagHelpersProvider> _tagHelpers;

Expand Down
2 changes: 1 addition & 1 deletion src/OrchardCore/OrchardCore/Extensions/ExtensionManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public sealed class ExtensionManager : IExtensionManager
private readonly ConcurrentDictionary<string, Lazy<IEnumerable<IFeatureInfo>>> _dependentFeatures = new();

private bool _isInitialized;
private readonly object _synLock = new();
private readonly Lock _synLock = new();

public ExtensionManager(
IServiceProvider serviceProvider,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace Microsoft.Extensions.Http;
internal sealed class ActiveHandlerTrackingEntry : IDisposable
{
private static readonly TimerCallback _timerCallback = (s) => ((ActiveHandlerTrackingEntry)s!).Timer_Tick();
private readonly object _lock;
private readonly Lock _lock;
private bool _timerInitialized;
private Timer _timer;
private TimerCallback _callback;
Expand All @@ -31,7 +31,7 @@ public ActiveHandlerTrackingEntry(
Scope = scope;
Lifetime = lifetime;

_lock = new object();
_lock = new();
}

public LifetimeTrackingHttpMessageHandler Handler { get; private set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ internal sealed class TenantHttpClientFactory : IHttpClientFactory, IHttpMessage
// There's no need for the factory itself to be disposable. If you stop using it, eventually everything will
// get reclaimed.
private Timer? _cleanupTimer;
private readonly object _cleanupTimerLock;
private readonly object _cleanupActiveLock;
private readonly Lock _cleanupTimerLock;
private readonly Lock _cleanupActiveLock;

// Collection of 'active' handlers.
//
Expand Down Expand Up @@ -94,8 +94,8 @@ public TenantHttpClientFactory(
_expiredHandlers = new ConcurrentQueue<ExpiredHandlerTrackingEntry>();
_expiryCallback = ExpiryTimer_Tick;

_cleanupTimerLock = new object();
_cleanupActiveLock = new object();
_cleanupTimerLock = new Lock();
_cleanupActiveLock = new Lock();

// We want to prevent a circular dependency between ILoggerFactory and IHttpClientFactory, in case
// any of ILoggerProvider instances use IHttpClientFactory to send logs to an external server.
Expand Down Expand Up @@ -274,7 +274,7 @@ internal void CleanupTimer_Tick()
// whether we need to start the timer.
StopCleanupTimer();

if (!Monitor.TryEnter(_cleanupActiveLock))
if (!_cleanupActiveLock.TryEnter())
{
// We don't want to run a concurrent cleanup cycle. This can happen if the cleanup cycle takes
// a long time for some reason. Since we're running user code inside Dispose, it's definitely
Expand Down Expand Up @@ -332,7 +332,7 @@ internal void CleanupTimer_Tick()
}
finally
{
Monitor.Exit(_cleanupActiveLock);
_cleanupActiveLock.Exit();
}

// We didn't totally empty the cleanup queue, try again later.
Expand Down
Loading