diff options
| author | Luke Pulverenti <luke.pulverenti@gmail.com> | 2013-04-02 22:59:27 -0400 |
|---|---|---|
| committer | Luke Pulverenti <luke.pulverenti@gmail.com> | 2013-04-02 22:59:27 -0400 |
| commit | fa884f3fead68522b45276661528ba39d42dcad1 (patch) | |
| tree | 28c77ebff10cae0e72bad5ff08815a9205ef0a67 /MediaBrowser.Common/Extensions | |
| parent | 713afcf6755b15142244cad6b16f8d539bd12893 (diff) | |
#62 - File locking problem in cache
Diffstat (limited to 'MediaBrowser.Common/Extensions')
| -rw-r--r-- | MediaBrowser.Common/Extensions/NamedLock.cs | 97 |
1 files changed, 0 insertions, 97 deletions
diff --git a/MediaBrowser.Common/Extensions/NamedLock.cs b/MediaBrowser.Common/Extensions/NamedLock.cs deleted file mode 100644 index d0164c70d..000000000 --- a/MediaBrowser.Common/Extensions/NamedLock.cs +++ /dev/null @@ -1,97 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Threading; -using System.Threading.Tasks; - -namespace MediaBrowser.Common.Extensions -{ - /// <summary> - /// Class NamedLock - /// </summary> - public class NamedLock : IDisposable - { - /// <summary> - /// The _locks - /// </summary> - private readonly Dictionary<string, SemaphoreSlim> _locks = new Dictionary<string, SemaphoreSlim>(); - - /// <summary> - /// Waits the async. - /// </summary> - /// <param name="name">The name.</param> - /// <returns>Task.</returns> - public Task WaitAsync(string name) - { - return GetLock(name).WaitAsync(); - } - - /// <summary> - /// Releases the specified name. - /// </summary> - /// <param name="name">The name.</param> - public void Release(string name) - { - SemaphoreSlim semaphore; - - if (_locks.TryGetValue(name, out semaphore)) - { - semaphore.Release(); - } - } - - /// <summary> - /// Gets the lock. - /// </summary> - /// <param name="filename">The filename.</param> - /// <returns>System.Object.</returns> - private SemaphoreSlim GetLock(string filename) - { - SemaphoreSlim fileLock; - lock (_locks) - { - if (!_locks.TryGetValue(filename, out fileLock)) - { - fileLock = new SemaphoreSlim(1,1); - _locks[filename] = fileLock; - } - } - return fileLock; - } - - /// <summary> - /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources. - /// </summary> - public void Dispose() - { - Dispose(true); - } - - /// <summary> - /// Releases unmanaged and - optionally - managed resources. - /// </summary> - /// <param name="dispose"><c>true</c> to release both managed and unmanaged resources; <c>false</c> to release only unmanaged resources.</param> - protected virtual void Dispose(bool dispose) - { - if (dispose) - { - DisposeLocks(); - } - } - - /// <summary> - /// Disposes the locks. - /// </summary> - private void DisposeLocks() - { - lock (_locks) - { - foreach (var semaphore in _locks.Values) - { - semaphore.Dispose(); - } - - _locks.Clear(); - } - } - } -} |
