Beispiel #1
0
 /// <summary>
 ///
 /// </summary>
 /// <returns></returns>
 /// throws ThreadInterruptedException.
 public T TakeFirst()
 {
     AccessLock.WaitOne();
     try {
         T x;
         while ((x = UnlinkFirst()) == null)
         {
             NotEmpty.WaitCondition(AccessLock);
         }
         return(x);
     } finally {
         try {
             AccessLock.ReleaseMutex();
         } catch (Exception) {
             throw new ThreadInterruptedException();
         }
     }
 }
Beispiel #2
0
 /**
  * Add to head of queue blocking until space if necessary.
  * @throws NullPointerException {@inheritDoc}
  * @throws InterruptedException {@inheritDoc}
  * throws ThreadInterruptedException.
  */
 public void PutFirst(T x)
 {
     if (x == null)
     {
         throw new System.NullReferenceException();
     }
     AccessLock.WaitOne();
     try {
         while (!LinkFirst(x))
         {
             NotFull.WaitCondition(AccessLock);
         }
     } finally {
         try {
             AccessLock.ReleaseMutex();
         } catch (Exception) {
             throw new ThreadInterruptedException();
         }
     }
 }
Beispiel #3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="cv"></param>
        /// <param name="cvLock"></param>
        /// <param name="millisecondsTimeout"></param>
        /// <returns></returns>
        /// throws ThreadInterruptedException.
        private int Wait(ConditionVariable cv, Mutex cvLock, int millisecondsTimeout)
        {
            long start = DateTime.UtcNow.Ticks;

            if (cv.WaitCondition(cvLock, millisecondsTimeout))
            {
                if (millisecondsTimeout > 0)
                {
                    long diff = DateTime.UtcNow.Ticks - start;
                    millisecondsTimeout -= (int)(diff / 10000);
                    if (millisecondsTimeout < 0)
                    {
                        millisecondsTimeout = 0;
                    }
                }
            }
            return(millisecondsTimeout);
        }