The Free Software Media System - Server Backend & API
move to new System.Threading.Lock type for better performance
Daniyar Alpyspayev2614fecf8df6
diff --git a/Emby.Server.Implementations/AppBase/BaseConfigurationManager.cs b/Emby.Server.Implementations/AppBase/BaseConfigurationManager.csindex 9e98d5ce09..9bc3a0204b 100644--- a/Emby.Server.Implementations/AppBase/BaseConfigurationManager.cs+++ b/Emby.Server.Implementations/AppBase/BaseConfigurationManager.cs@@ -4,6 +4,7 @@ using System.Collections.Generic;using System.Globalization;using System.IO;using System.Linq;+using System.Threading;using MediaBrowser.Common.Configuration;using MediaBrowser.Common.Events;using MediaBrowser.Common.Extensions;@@ -19,7 +20,7 @@ namespace Emby.Server.Implementations.AppBasepublic abstract class BaseConfigurationManager : IConfigurationManager{private readonly ConcurrentDictionary<string, object> _configurations = new();- private readonly object _configurationSyncLock = new();+ private readonly Lock _configurationSyncLock = new();private ConfigurationStore[] _configurationStores = Array.Empty<ConfigurationStore>();private IConfigurationFactory[] _configurationFactories = Array.Empty<IConfigurationFactory>();diff --git a/Emby.Server.Implementations/Devices/DeviceId.cs b/Emby.Server.Implementations/Devices/DeviceId.csindex 2459178d81..0b3c3bbd4f 100644--- a/Emby.Server.Implementations/Devices/DeviceId.cs+++ b/Emby.Server.Implementations/Devices/DeviceId.cs@@ -4,6 +4,7 @@ using System;using System.Globalization;using System.IO;using System.Text;+using System.Threading;using MediaBrowser.Common.Configuration;using Microsoft.Extensions.Logging;@@ -13,7 +14,7 @@ namespace Emby.Server.Implementations.Devices{private readonly IApplicationPaths _appPaths;private readonly ILogger<DeviceId> _logger;- private readonly object _syncLock = new object();+ private readonly Lock _syncLock = new();private string? _id;diff --git a/Emby.Server.Implementations/EntryPoints/LibraryChangedNotifier.cs b/Emby.Server.Implementations/EntryPoints/LibraryChangedNotifier.csindex 4c668379c8..fb0a55135f 100644--- a/Emby.Server.Implementations/EntryPoints/LibraryChangedNotifier.cs+++ b/Emby.Server.Implementations/EntryPoints/LibraryChangedNotifier.cs@@ -34,7 +34,7 @@ public sealed class LibraryChangedNotifier : IHostedService, IDisposableprivate readonly IUserManager _userManager;private readonly ILogger<LibraryChangedNotifier> _logger;- private readonly object _libraryChangedSyncLock = new();+ private readonly Lock _libraryChangedSyncLock = new();private readonly List<Folder> _foldersAddedTo = new();private readonly List<Folder> _foldersRemovedFrom = new();private readonly List<BaseItem> _itemsAdded = new();diff --git a/Emby.Server.Implementations/EntryPoints/UserDataChangeNotifier.cs b/Emby.Server.Implementations/EntryPoints/UserDataChangeNotifier.csindex aef02ce6bf..aa1c3064bc 100644--- a/Emby.Server.Implementations/EntryPoints/UserDataChangeNotifier.cs+++ b/Emby.Server.Implementations/EntryPoints/UserDataChangeNotifier.cs@@ -24,7 +24,7 @@ namespace Emby.Server.Implementations.EntryPointsprivate readonly IUserManager _userManager;private readonly Dictionary<Guid, List<BaseItem>> _changedItems = new();- private readonly object _syncLock = new();+ private readonly Lock _syncLock = new();private Timer? _updateTimer;diff --git a/Emby.Server.Implementations/IO/FileRefresher.cs b/Emby.Server.Implementations/IO/FileRefresher.csindex e75cab64c9..7378cf8851 100644--- a/Emby.Server.Implementations/IO/FileRefresher.cs+++ b/Emby.Server.Implementations/IO/FileRefresher.cs@@ -18,8 +18,8 @@ namespace Emby.Server.Implementations.IOprivate readonly ILibraryManager _libraryManager;private readonly IServerConfigurationManager _configurationManager;- private readonly List<string> _affectedPaths = new List<string>();- private readonly object _timerLock = new object();+ private readonly List<string> _affectedPaths = new();+ private readonly Lock _timerLock = new();private Timer? _timer;private bool _disposed;diff --git a/Emby.Server.Implementations/Library/LibraryManager.cs b/Emby.Server.Implementations/Library/LibraryManager.csindex 28f7ed6598..2d1af82b31 100644--- a/Emby.Server.Implementations/Library/LibraryManager.cs+++ b/Emby.Server.Implementations/Library/LibraryManager.cs@@ -81,8 +81,8 @@ namespace Emby.Server.Implementations.Library/// <summary>/// The _root folder sync lock./// </summary>- private readonly object _rootFolderSyncLock = new object();- private readonly object _userRootFolderSyncLock = new object();+ private readonly Lock _rootFolderSyncLock = new();+ private readonly Lock _userRootFolderSyncLock = new();private readonly TimeSpan _viewRefreshInterval = TimeSpan.FromHours(24);diff --git a/Emby.Server.Implementations/ScheduledTasks/ScheduledTaskWorker.cs b/Emby.Server.Implementations/ScheduledTasks/ScheduledTaskWorker.csindex fe769baf92..0bc67bc47d 100644--- a/Emby.Server.Implementations/ScheduledTasks/ScheduledTaskWorker.cs+++ b/Emby.Server.Implementations/ScheduledTasks/ScheduledTaskWorker.cs@@ -27,7 +27,7 @@ namespace Emby.Server.Implementations.ScheduledTasksprivate readonly IApplicationPaths _applicationPaths;private readonly ILogger _logger;private readonly ITaskManager _taskManager;- private readonly object _lastExecutionResultSyncLock = new();+ private readonly Lock _lastExecutionResultSyncLock = new();private bool _readFromFile;private TaskResult _lastExecutionResult;private Task _currentTask;diff --git a/Emby.Server.Implementations/Session/SessionWebSocketListener.cs b/Emby.Server.Implementations/Session/SessionWebSocketListener.csindex aba51de8f5..c4f6a6285b 100644--- a/Emby.Server.Implementations/Session/SessionWebSocketListener.cs+++ b/Emby.Server.Implementations/Session/SessionWebSocketListener.cs@@ -41,7 +41,7 @@ namespace Emby.Server.Implementations.Session/// <summary>/// Lock used for accessing the WebSockets watchlist./// </summary>- private readonly object _webSocketsLock = new object();+ private readonly Lock _webSocketsLock = new();private readonly ISessionManager _sessionManager;private readonly ILogger<SessionWebSocketListener> _logger;diff --git a/Emby.Server.Implementations/SyncPlay/SyncPlayManager.cs b/Emby.Server.Implementations/SyncPlay/SyncPlayManager.csindex 00c655634a..fdfff8f3b8 100644--- a/Emby.Server.Implementations/SyncPlay/SyncPlayManager.cs+++ b/Emby.Server.Implementations/SyncPlay/SyncPlayManager.cs@@ -67,7 +67,7 @@ namespace Emby.Server.Implementations.SyncPlay/// <remarks>/// This lock has priority on locks made on <see cref="Group"/>./// </remarks>- private readonly object _groupsLock = new object();+ private readonly Lock _groupsLock = new();private bool _disposed = false;diff --git a/Emby.Server.Implementations/Updates/InstallationManager.cs b/Emby.Server.Implementations/Updates/InstallationManager.csindex ce3d6cab88..c4d697be5b 100644--- a/Emby.Server.Implementations/Updates/InstallationManager.cs+++ b/Emby.Server.Implementations/Updates/InstallationManager.cs@@ -48,7 +48,7 @@ namespace Emby.Server.Implementations.Updates/// </summary>/// <value>The application host.</value>private readonly IServerApplicationHost _applicationHost;- private readonly object _currentInstallationsLock = new object();+ private readonly Lock _currentInstallationsLock = new();/// <summary>/// The current installations.diff --git a/MediaBrowser.Common/Plugins/BasePluginOfT.cs b/MediaBrowser.Common/Plugins/BasePluginOfT.csindex bf2f12cb9b..58992ecd73 100644--- a/MediaBrowser.Common/Plugins/BasePluginOfT.cs+++ b/MediaBrowser.Common/Plugins/BasePluginOfT.cs@@ -4,6 +4,7 @@using System;using System.IO;using System.Runtime.InteropServices;+using System.Threading;using MediaBrowser.Common.Configuration;using MediaBrowser.Model.Plugins;using MediaBrowser.Model.Serialization;@@ -20,12 +21,12 @@ namespace MediaBrowser.Common.Plugins/// <summary>/// The configuration sync lock./// </summary>- private readonly object _configurationSyncLock = new object();+ private readonly Lock _configurationSyncLock = new();/// <summary>/// The configuration save lock./// </summary>- private readonly object _configurationSaveLock = new object();+ private readonly Lock _configurationSaveLock = new();/// <summary>/// The configuration.diff --git a/MediaBrowser.Controller/Entities/AggregateFolder.cs b/MediaBrowser.Controller/Entities/AggregateFolder.csindex 40cdd6c91e..5e0d1bb455 100644--- a/MediaBrowser.Controller/Entities/AggregateFolder.cs+++ b/MediaBrowser.Controller/Entities/AggregateFolder.cs@@ -23,7 +23,7 @@ namespace MediaBrowser.Controller.Entities/// </summary>public class AggregateFolder : Folder{- private readonly object _childIdsLock = new object();+ private readonly Lock _childIdsLock = new();/// <summary>/// The _virtual children.diff --git a/MediaBrowser.Controller/Entities/UserRootFolder.cs b/MediaBrowser.Controller/Entities/UserRootFolder.csindex a687adeddc..65d81b23e4 100644--- a/MediaBrowser.Controller/Entities/UserRootFolder.cs+++ b/MediaBrowser.Controller/Entities/UserRootFolder.cs@@ -21,7 +21,7 @@ namespace MediaBrowser.Controller.Entities/// </summary>public class UserRootFolder : Folder{- private readonly object _childIdsLock = new object();+ private readonly Lock _childIdsLock = new();private List<Guid> _childrenIds = null;/// <summary>diff --git a/MediaBrowser.Controller/MediaEncoding/TranscodingJob.cs b/MediaBrowser.Controller/MediaEncoding/TranscodingJob.csindex fefa66cdb8..56990d0b82 100644--- a/MediaBrowser.Controller/MediaEncoding/TranscodingJob.cs+++ b/MediaBrowser.Controller/MediaEncoding/TranscodingJob.cs@@ -12,8 +12,8 @@ namespace MediaBrowser.Controller.MediaEncoding;public sealed class TranscodingJob : IDisposable{private readonly ILogger<TranscodingJob> _logger;- private readonly object _processLock = new();- private readonly object _timerLock = new();+ private readonly Lock _processLock = new();+ private readonly Lock _timerLock = new();private Timer? _killTimer;diff --git a/MediaBrowser.Controller/Net/BasePeriodicWebSocketListener.cs b/MediaBrowser.Controller/Net/BasePeriodicWebSocketListener.csindex a47d2fa45d..4757bfa303 100644--- a/MediaBrowser.Controller/Net/BasePeriodicWebSocketListener.cs+++ b/MediaBrowser.Controller/Net/BasePeriodicWebSocketListener.cs@@ -33,7 +33,7 @@ namespace MediaBrowser.Controller.NetSingleWriter = false});- private readonly object _activeConnectionsLock = new();+ private readonly Lock _activeConnectionsLock = new();/// <summary>/// The _active connections.diff --git a/MediaBrowser.Controller/Session/SessionInfo.cs b/MediaBrowser.Controller/Session/SessionInfo.csindex 3ba1bfce42..cbef5d0113 100644--- a/MediaBrowser.Controller/Session/SessionInfo.cs+++ b/MediaBrowser.Controller/Session/SessionInfo.cs@@ -25,7 +25,7 @@ namespace MediaBrowser.Controller.Sessionprivate readonly ISessionManager _sessionManager;private readonly ILogger _logger;- private readonly object _progressLock = new();+ private readonly Lock _progressLock = new();private Timer _progressTimer;private PlaybackProgressInfo _lastProgressInfo;diff --git a/MediaBrowser.MediaEncoding/Encoder/MediaEncoder.cs b/MediaBrowser.MediaEncoding/Encoder/MediaEncoder.csindex a34238cd68..e084bda27a 100644--- a/MediaBrowser.MediaEncoding/Encoder/MediaEncoder.cs+++ b/MediaBrowser.MediaEncoding/Encoder/MediaEncoder.cs@@ -62,7 +62,7 @@ namespace MediaBrowser.MediaEncoding.Encoderprivate readonly AsyncNonKeyedLocker _thumbnailResourcePool;- private readonly object _runningProcessesLock = new object();+ private readonly Lock _runningProcessesLock = new();private readonly List<ProcessWrapper> _runningProcesses = new List<ProcessWrapper>();// MediaEncoder is registered as a Singletondiff --git a/MediaBrowser.Providers/Manager/ProviderManager.cs b/MediaBrowser.Providers/Manager/ProviderManager.csindex 010e9c3b63..854ac6b9c9 100644--- a/MediaBrowser.Providers/Manager/ProviderManager.cs+++ b/MediaBrowser.Providers/Manager/ProviderManager.cs@@ -48,7 +48,7 @@ namespace MediaBrowser.Providers.Manager/// </summary>public class ProviderManager : IProviderManager, IDisposable{- private readonly object _refreshQueueLock = new();+ private readonly Lock _refreshQueueLock = new();private readonly ILogger<ProviderManager> _logger;private readonly IHttpClientFactory _httpClientFactory;private readonly ILibraryMonitor _libraryMonitor;diff --git a/src/Jellyfin.LiveTv/Timers/ItemDataProvider.cs b/src/Jellyfin.LiveTv/Timers/ItemDataProvider.csindex 9e7323f5b9..6a68b8c25c 100644--- a/src/Jellyfin.LiveTv/Timers/ItemDataProvider.cs+++ b/src/Jellyfin.LiveTv/Timers/ItemDataProvider.cs@@ -6,6 +6,7 @@ using System.Diagnostics.CodeAnalysis;using System.IO;using System.Linq;using System.Text.Json;+using System.Threading;using Jellyfin.Extensions.Json;using Microsoft.Extensions.Logging;@@ -15,7 +16,7 @@ namespace Jellyfin.LiveTv.Timerswhere T : class{private readonly string _dataPath;- private readonly object _fileDataLock = new object();+ private readonly Lock _fileDataLock = new();private readonly JsonSerializerOptions _jsonOptions = JsonDefaults.Options;private T[]? _items;diff --git a/src/Jellyfin.Networking/Manager/NetworkManager.cs b/src/Jellyfin.Networking/Manager/NetworkManager.csindex 10aed673b1..b1fc5d406c 100644--- a/src/Jellyfin.Networking/Manager/NetworkManager.cs+++ b/src/Jellyfin.Networking/Manager/NetworkManager.cs@@ -27,7 +27,7 @@ public class NetworkManager : INetworkManager, IDisposable/// <summary>/// Threading lock for network properties./// </summary>- private readonly object _initLock;+ private readonly Lock _initLock;private readonly ILogger<NetworkManager> _logger;@@ -35,7 +35,7 @@ public class NetworkManager : INetworkManager, IDisposableprivate readonly IConfiguration _startupConfig;- private readonly object _networkEventLock;+ private readonly Lock _networkEventLock;/// <summary>/// Holds the published server URLs and the IPs to use them on.@@ -93,7 +93,7 @@ public class NetworkManager : INetworkManager, IDisposable_interfaces = new List<IPData>();_macAddresses = new List<PhysicalAddress>();_publishedServerUrls = new List<PublishedServerUriOverride>();- _networkEventLock = new object();+ _networkEventLock = new();_remoteAddressFilter = new List<IPNetwork>();_ = bool.TryParse(startupConfig[DetectNetworkChangeKey], out var detectNetworkChange);