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