网上演练
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

38 lines
912 B

#if FAT
using System;
using System.Threading;
namespace LinqInternal.Threading.Needles
{
internal sealed class LockableContext
{
internal readonly LockContext<Thread> Context;
private readonly StructNeedle<TrackingThreadLocal<LockableSlot>> _slots;
public LockableContext(int capacity)
{
Context = new LockContext<Thread>(capacity);
_slots.Value = new TrackingThreadLocal<LockableSlot>(() => null);
}
internal LockableSlot Slot
{
get { return _slots.Value.Value; }
set { _slots.Value.Value = value; }
}
public IDisposable Enter()
{
return new LockableSlot(this);
}
internal bool TryGetSlot(out LockableSlot slot)
{
return _slots.Value.TryGetValue(Thread.CurrentThread, out slot) && slot != null;
}
}
}
#endif