public void Enqueue(WaitNode w) { if (_tail == null) { _head = _tail = w; } else { _tail.NextWaitNode = w; _tail = w; } }
public WaitNode Dequeue() { if (_head == null) { return(null); } var w = _head; _head = w.NextWaitNode; if (_head == null) { _tail = null; } w.NextWaitNode = null; return(w); }
public void TakeOver(WaitNode node) { lock (this) { Debug.Assert(_holds == 1 && _owner == Thread.CurrentThread); _owner = node.Owner; } }
public override bool TryLock(TimeSpan timespan) { var caller = Thread.CurrentThread; lock (this) { if (GetHold(caller)) return true; } var n = new WaitNode(); return n.DoTimedWait(this, timespan); }
public override void LockInterruptibly() { var caller = Thread.CurrentThread; lock (this) { if (GetHold(caller)) return; } var n = new WaitNode(); n.DoWait(this); }
public bool Recheck(WaitNode node) { var caller = Thread.CurrentThread; lock (this) { if (GetHold(caller)) return true; _wq.Enqueue(node); return false; } }
public void Enqueue(WaitNode w) { if (_tail == null) _head = _tail = w; else { _tail.NextWaitNode = w; _tail = w; } }
public WaitNode Dequeue() { if (_head == null) return null; var w = _head; _head = w.NextWaitNode; if (_head == null) _tail = null; w.NextWaitNode = null; return w; }
public void TakeOver(WaitNode node) { }
public bool Recheck(WaitNode node) { return false; }
private void DoWait(Action<WaitNode> action) { var holdCount = Lock.HoldCount; if (holdCount == 0) { throw new SynchronizationLockException(); } var n = new WaitNode(); _wq.Enqueue(n); for (var i = holdCount; i > 0; i--) Lock.Unlock(); try { action(n); } finally { for (var i = holdCount; i > 0; i--) Lock.Lock(); } }