This repository has been archived on 2023-02-02. You can view files and clone it, but cannot push or open issues or pull requests.
mfgames-locking-cil/MfGames.Locking/UpgradableLock.cs
Dylan R. E. Moonfire f01a18a15a Initial commit.
2018-01-18 16:16:01 -06:00

37 lines
1.2 KiB
C#

// <copyright file="UpgradableLock.cs" company="Moonfire Games">
// Copyright (c) Moonfire Games.
// This code is licensed under the MIT license.
// See LICENSE.md in the source or https://opensource.org/licenses/MIT
// </copyright>
namespace MfGames.Locking
{
using System;
using System.Threading;
/// <summary>
/// Defines a ReaderWriterLockSlim read-only lock.
/// </summary>
public class UpgradableLock : IDisposable
{
private readonly ReaderWriterLockSlim readerWriterLockSlim;
/// <summary>
/// Initializes a new instance of the <see cref="UpgradableLock" /> class.
/// </summary>
/// <param name="readerWriterLockSlim">The reader writer lock slim.</param>
public UpgradableLock(ReaderWriterLockSlim readerWriterLockSlim)
{
this.readerWriterLockSlim = readerWriterLockSlim;
readerWriterLockSlim.EnterUpgradeableReadLock();
}
/// <summary>
/// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
/// </summary>
public void Dispose()
{
this.readerWriterLockSlim.ExitUpgradeableReadLock();
}
}
}