public void SignalOnWaitingThread() { WaitNode node = new WaitNode(); IQueuedSync mockQueuedSync = MockRepository.GenerateMock <IQueuedSync>(); node.Signal(mockQueuedSync); mockQueuedSync.AssertWasCalled(m => m.TakeOver(node)); }
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 void Enqueue(WaitNode waitNode) { if (_tail == null) _head = _tail = waitNode; else { _tail.NextWaitNode = waitNode; _tail = waitNode; } }
public void WaitingThreads() { WaitNode node = new WaitNode(); FIFOWaitQueue queue = new FIFOWaitQueue(); Assert.AreEqual(0, queue.WaitingThreads.Count); Assert.IsFalse(queue.IsWaiting(Thread.CurrentThread)); queue.Enqueue(node); Assert.AreEqual(1, queue.WaitingThreads.Count); Assert.IsTrue(queue.IsWaiting(Thread.CurrentThread)); }
public void Enqueue(WaitNode w) { if (_tail == null) { _head = _tail = w; } else { _tail.NextWaitNode = w; _tail = w; } }
public void EnqueueAndDequeueElements() { WaitNode node = new WaitNode(); WaitNode node1 = new WaitNode(); FIFOWaitQueue queue = new FIFOWaitQueue(); Assert.AreEqual(null, queue.Dequeue()); queue.Enqueue(node1); queue.Enqueue(node); Assert.AreEqual(2, queue.Length); Assert.IsTrue(queue.HasNodes); Assert.AreEqual(node1, queue.Dequeue()); Assert.AreEqual(node, queue.Dequeue()); Assert.IsFalse(queue.HasNodes); }
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 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(); } }
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 (_owner == null) { _owner = caller; _holds = 1; return true; } else if (caller == _owner) { ++_holds; 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) { lock (this) { Thread caller = Thread.CurrentThread; if (_owner == null) { _owner = caller; _holds = 1; return true; } else if (caller == _owner) { ++_holds; return true; } _wq.Enqueue(node); return false; } }
public override void LockInterruptibly() { Thread caller = Thread.CurrentThread; lock (this) { if (_owner == null) { _owner = caller; _holds = 1; return; } else if (caller == _owner) { ++_holds; return; } } WaitNode n = new WaitNode(); n.DoWait(this); }
public bool Recheck(WaitNode node) { Thread caller = Thread.CurrentThread; lock (this) { if(GetHold(caller)) return true; _wq.Enqueue(node); return false; } }
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); }