using System;
using System.Threading;
namespace IFramework.Net
{
///
/// 自旋锁
///
public sealed class LockWait : IDisposable
{
private LockParam _param = null;
///
/// Ctor
///
///
public LockWait(ref LockParam param)
{
this._param = param;
while (Interlocked.CompareExchange(ref param.signal, 1, 0) == 1)
{
Thread.Sleep(param.sleepInterval);
}
}
///
/// 释放
///
public void Dispose()
{
Interlocked.Exchange(ref _param.signal, 0);
}
}
///
/// 自旋锁信号
///
public class LockParam
{
internal int signal = 0;
internal int sleepInterval = 1;
}
}