public int AddParticipants(int participantCount) { // Basically, we try to add ourselves and return // the phase. If the call return false, we repeatdly try // to add ourselves for the next phase do { if (cntd.TryAddCount(participantCount)) { Interlocked.Add(ref participants, participantCount); return(phase); } } while (true); }
public long AddParticipants(int participantCount) { if (cleaned) { throw GetDisposed(); } if (participantCount < 0) { throw new InvalidOperationException(); } // Basically, we try to add ourselves and return // the phase. If the call return false, we repeatdly try // to add ourselves for the next phase do { if (cntd.TryAddCount(participantCount)) { Interlocked.Add(ref participants, participantCount); return(phase); } } while (true); }
public void TryAddCount_HasBeenSet () { var ev = new CountdownEvent (0); Assert.IsFalse (ev.TryAddCount (1), "#1"); ev = new CountdownEvent (1); ev.Signal (); Assert.IsFalse (ev.TryAddCount (1), "#2"); ev = new CountdownEvent (2); ev.Signal (2); Assert.IsFalse (ev.TryAddCount (66), "#3"); }
public void TryAddCount_Invalid () { var ev = new CountdownEvent (1); try { ev.TryAddCount (0); Assert.Fail ("#1"); } catch (ArgumentOutOfRangeException) { } try { ev.TryAddCount (-1); Assert.Fail ("#2"); } catch (ArgumentOutOfRangeException) { } }
public void TryAddCountTestCase() { var evt = new CountdownEvent (5); Assert.IsTrue(evt.TryAddCount(2), "#1"); evt.Signal(7); Assert.IsFalse(evt.TryAddCount(), "#2"); }
public void Dispose () { var ce = new CountdownEvent (1); ce.Dispose (); Assert.AreEqual (1, ce.CurrentCount, "#0a"); Assert.AreEqual (1, ce.InitialCount, "#0b"); Assert.IsFalse (ce.IsSet, "#0c"); try { ce.AddCount (); Assert.Fail ("#1"); } catch (ObjectDisposedException) { } try { ce.Reset (); Assert.Fail ("#2"); } catch (ObjectDisposedException) { } try { ce.Signal (); Assert.Fail ("#3"); } catch (ObjectDisposedException) { } try { ce.TryAddCount (); Assert.Fail ("#4"); } catch (ObjectDisposedException) { } try { ce.Wait (5); Assert.Fail ("#4"); } catch (ObjectDisposedException) { } try { var v = ce.WaitHandle; Assert.Fail ("#5"); } catch (ObjectDisposedException) { } }
public void CurrentCountTestCase() { var evt = new CountdownEvent (5); Assert.AreEqual(5, evt.CurrentCount, "#1"); evt.AddCount(); Assert.AreEqual(6, evt.CurrentCount, "#2"); evt.TryAddCount(2); Assert.AreEqual(8, evt.CurrentCount, "#3"); evt.Signal(4); Assert.AreEqual(4, evt.CurrentCount, "#4"); evt.Reset(); Assert.AreEqual(5, evt.CurrentCount, "#5"); }