37 lines
1.2 KiB
C#
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();
|
|
}
|
|
}
|
|
}
|