public override void Take() { if (PreCheck()) { return; } WaitNode w = new WaitNode(); w.DoWait(this); }
internal WaitNode GetSignallee() { lock (this) { WaitNode w = Queue.Extract(); if (w == null) { ++Permits; // if none, inc permits for new arrivals } return(w); } }
public override void Insert(WaitNode node) { if (tail_ == null) { head_ = tail_ = node; } else { tail_.Next = node; tail_ = node; } }
public override bool Take(TimeSpan timeout) { if (PreCheck()) { return(true); } if (timeout.TotalMilliseconds <= 0) { return(false); } WaitNode w = new WaitNode(); return(w.DoTimedWait(this, timeout)); }
public override void Release() { while (true) { WaitNode w = GetSignallee(); if (w == null) { return; // no one to signal } if (w.Signal()) { return; // notify if still waiting, else skip } } }
internal bool ReCheck(WaitNode w) { lock (this) { bool pass = (Permits > 0); if (pass) { --Permits; } else { Queue.Insert(w); } return(pass); } }
public override WaitNode Extract() { if (head_ == null) { return(null); } else { WaitNode w = head_; head_ = w.Next; if (head_ == null) { tail_ = null; } w.Next = null; return(w); } }
public abstract void Insert(WaitNode node);