Files
Umbraco-CMS/src/Umbraco.Core/UpgradeableReadLock.cs
shannon@ShandemVaio 5fcd8b1d52 Fixed file names of ReadLock and UpradeableReadLock. Fixes up UpgradeableReadLock to ensure
that it it is upgraded it releases its writelock on dispose. Fixes up RouteLookups to have
correct locking. Fixes up library to resolve the NiceUrlResolver using the UmbracoContext.Current
singleton acessor.
2012-07-23 23:03:00 +06:00

46 lines
1.1 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
namespace Umbraco.Core
{
/// <summary>
/// Provides a convenience methodology for implementing locked access to resources.
/// </summary>
/// <remarks>
/// Intended as an infrastructure class.
/// </remarks>
public class UpgradeableReadLock : IDisposable
{
private readonly ReaderWriterLockSlim _rwLock;
private bool _upgraded = false;
/// <summary>
/// Initializes a new instance of the <see cref="ReadLock"/> class.
/// </summary>
/// <param name="rwLock">The rw lock.</param>
public UpgradeableReadLock(ReaderWriterLockSlim rwLock)
{
_rwLock = rwLock;
_rwLock.EnterUpgradeableReadLock();
}
public void UpgradeToWriteLock()
{
_rwLock.EnterWriteLock();
_upgraded = true;
}
void IDisposable.Dispose()
{
if (_upgraded)
{
_rwLock.ExitWriteLock();
}
_rwLock.ExitUpgradeableReadLock();
}
}
}