예제 #1
0
        public override void Take()
        {
            if (PreCheck())
            {
                return;
            }
            WaitNode w = new WaitNode();

            w.DoWait(this);
        }
예제 #2
0
 internal WaitNode GetSignallee()
 {
     lock (this)
     {
         WaitNode w = Queue.Extract();
         if (w == null)
         {
             ++Permits;            // if none, inc permits for new arrivals
         }
         return(w);
     }
 }
예제 #3
0
 public override void Insert(WaitNode node)
 {
     if (tail_ == null)
     {
         head_ = tail_ = node;
     }
     else
     {
         tail_.Next = node;
         tail_      = node;
     }
 }
예제 #4
0
        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));
        }
예제 #5
0
 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
         }
     }
 }
예제 #6
0
 internal bool ReCheck(WaitNode w)
 {
     lock (this)
     {
         bool pass = (Permits > 0);
         if (pass)
         {
             --Permits;
         }
         else
         {
             Queue.Insert(w);
         }
         return(pass);
     }
 }
예제 #7
0
 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);
     }
 }
예제 #8
0
 public abstract void Insert(WaitNode node);