90 lines
1.4 KiB
C#
90 lines
1.4 KiB
C#
using System;
|
|
namespace PingPong.Generic
|
|
{
|
|
|
|
public class Locked<T>
|
|
{
|
|
#region Members
|
|
|
|
/// <summary>
|
|
/// The lock object.
|
|
/// </summary>
|
|
private object lockObject;
|
|
/// <summary>
|
|
/// The value.
|
|
/// </summary>
|
|
private T value;
|
|
/// <summary>
|
|
/// The is locked.
|
|
/// </summary>
|
|
private bool isLocked;
|
|
|
|
#endregion
|
|
|
|
#region Properties
|
|
|
|
/// <summary>
|
|
/// Gets or sets the value.
|
|
/// </summary>
|
|
/// <value>
|
|
/// The value.
|
|
/// </value>
|
|
public T Value
|
|
{
|
|
get
|
|
{
|
|
return this.value;
|
|
}
|
|
set
|
|
{
|
|
lock (this.lockObject)
|
|
{
|
|
this.isLocked = true;
|
|
this.value = value;
|
|
this.isLocked = false;
|
|
}
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Gets a value indicating whether this instance is locked.
|
|
/// </summary>
|
|
/// <value>
|
|
/// <c>true</c> if this instance is locked; otherwise, <c>false</c>.
|
|
/// </value>
|
|
public bool IsLocked
|
|
{
|
|
get
|
|
{
|
|
return this.isLocked;
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Constructors
|
|
|
|
/// <summary>
|
|
/// Initializes a new instance of the <see cref="PingPong.Generic.Locked`1"/> class.
|
|
/// </summary>
|
|
public Locked()
|
|
{
|
|
this.value = default(T);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Initializes a new instance of the <see cref="PingPong.Generic.Locked`1"/> class.
|
|
/// </summary>
|
|
/// <param name='value'>
|
|
/// Value.
|
|
/// </param>
|
|
public Locked(T value)
|
|
{
|
|
this.value = value;
|
|
}
|
|
|
|
#endregion
|
|
}
|
|
}
|
|
|