Example #1
0
        public void Wait()
        {
            if (_waitQueue == null)
            {
                _waitQueue = new Queue <LockerEvent>();
            }

            LockerEvent e = acquireEvent();

            try
            {
                _waitQueue.Enqueue(e);

                //
                // Preserve the lock count until we reaquire the lock.
                //
                int lockCount = _lockCount;
                _lockCount = 0;

                //
                // Fully release the lock.
                //
                for (int i = 0; i < lockCount; ++i)
                {
                    _mutex.ReleaseMutex();
                }

                //
                // Wait for the event to be set.
                //
                e.ev.WaitOne();

                //
                // Reacquire the lock the same number of times.
                //
                for (int i = 0; i < lockCount; ++i)
                {
                    _mutex.WaitOne();
                }

                _lockCount = lockCount;

                Debug.Assert(e.notified);
            }
            finally
            {
                releaseEvent(e);
            }
        }
Example #2
0
 private LockerEvent acquireEvent()
 {
     if (_eventPool == null)
     {
         return(new LockerEvent());
     }
     else
     {
         LockerEvent l = _eventPool;
         _eventPool = _eventPool.next;
         l.Reset();
         l.next = null;
         return(l);
     }
 }
Example #3
0
 public void Notify()
 {
     if (_waitQueue != null)
     {
         while (_waitQueue.Count > 0)
         {
             //
             // Set the first event in the wait queue.
             //
             LockerEvent h = _waitQueue.Dequeue();
             h.notified = true;
             h.ev.Set();
         }
     }
 }
Example #4
0
 internal LockerEvent()
 {
     ev = new System.Threading.ManualResetEvent(false);
     next = null;
 }
Example #5
0
 private void releaseEvent(LockerEvent e)
 {
     e.next = _eventPool;
     _eventPool = e;
 }
Example #6
0
 internal LockerEvent()
 {
     ev   = new System.Threading.ManualResetEvent(false);
     next = null;
 }
Example #7
0
 private void releaseEvent(LockerEvent e)
 {
     e.next     = _eventPool;
     _eventPool = e;
 }