2017-10-03 19:17:35 -04:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
2018-04-08 02:44:42 -04:00
|
|
|
|
namespace SharedLibraryCore.Helpers
|
2017-10-03 19:17:35 -04:00
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Excuse this monstrosity
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <typeparam name="T"></typeparam>
|
|
|
|
|
public class ThreadSafe<T>
|
|
|
|
|
{
|
|
|
|
|
private bool _lock;
|
|
|
|
|
private T instance;
|
|
|
|
|
|
|
|
|
|
public ThreadSafe(T instance)
|
|
|
|
|
{
|
|
|
|
|
this.instance = instance;
|
|
|
|
|
_lock = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public T Value
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
// shush
|
|
|
|
|
if (_lock)
|
|
|
|
|
return Value;
|
|
|
|
|
_lock = true;
|
|
|
|
|
return instance;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
if (_lock)
|
|
|
|
|
{
|
|
|
|
|
Value = Value;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
instance = Value;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|