From 9663252d10224a41bb35da006c8bd0248b98c169 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Mon, 7 Oct 2013 23:06:12 -0400 Subject: remove mutex from mono startup --- .../Session/SessionManager.cs | 38 ++++++++-------------- 1 file changed, 13 insertions(+), 25 deletions(-) (limited to 'MediaBrowser.Server.Implementations') diff --git a/MediaBrowser.Server.Implementations/Session/SessionManager.cs b/MediaBrowser.Server.Implementations/Session/SessionManager.cs index d3b6bc59f..9fb9010e5 100644 --- a/MediaBrowser.Server.Implementations/Session/SessionManager.cs +++ b/MediaBrowser.Server.Implementations/Session/SessionManager.cs @@ -44,13 +44,11 @@ namespace MediaBrowser.Server.Implementations.Session /// The configuration manager. private readonly IServerConfigurationManager _configurationManager; - private object _sessionLock = new object(); - /// /// The _active connections /// - private readonly Dictionary _activeConnections = - new Dictionary(StringComparer.OrdinalIgnoreCase); + private readonly ConcurrentDictionary _activeConnections = + new ConcurrentDictionary(StringComparer.OrdinalIgnoreCase); /// /// Occurs when [playback start]. @@ -86,7 +84,7 @@ namespace MediaBrowser.Server.Implementations.Session /// All connections. public IEnumerable Sessions { - get { return _activeConnections.Values.ToList().OrderByDescending(c => c.LastActivityDate); } + get { return _activeConnections.Values.OrderByDescending(c => c.LastActivityDate).ToList(); } } /// @@ -195,28 +193,18 @@ namespace MediaBrowser.Server.Implementations.Session { var key = clientType + deviceId + appVersion; - lock (_sessionLock) + var connection = _activeConnections.GetOrAdd(key, keyName => new SessionInfo { - SessionInfo connection; + Client = clientType, + DeviceId = deviceId, + ApplicationVersion = appVersion, + Id = Guid.NewGuid() + }); - if (!_activeConnections.TryGetValue(key, out connection)) - { - connection = new SessionInfo - { - Client = clientType, - DeviceId = deviceId, - ApplicationVersion = appVersion, - Id = Guid.NewGuid() - }; - - _activeConnections[key] = connection; - } + connection.DeviceName = deviceName; + connection.User = user; - connection.DeviceName = deviceName; - connection.User = user; - - return connection; - } + return connection; } /// @@ -589,4 +577,4 @@ namespace MediaBrowser.Server.Implementations.Session return Task.WhenAll(tasks); } } -} +} \ No newline at end of file -- cgit v1.2.3