Beispiel #1
0
	    public void Enqueue(WaitNode w)
		{
			if (_tail == null)
			    _head = _tail = w;
			else
			{
			    _tail.NextWaitNode = w;
			    _tail = w;
			}
		}
 public void Enqueue(WaitNode w)
 {
     if (_tail == null)
     {
         _head = _tail = w;
     }
     else
     {
         _tail.NextWaitNode = w;
         _tail = w;
     }
 }
        // In backport 3.1 but not used.
        //public void PutBack(WaitNode w)
        //{
        //    w.NextWaitNode = _head;
        //    _head = w;
        //    if (_tail == null)
        //        _tail = w;
        //}

        public bool IsWaiting(Thread thread)
        {
            if (thread == null)
            {
                throw new ArgumentNullException("thread");
            }
            for (WaitNode node = _head; node != null; node = node.NextWaitNode)
            {
                if (node.IsWaiting && node.Owner == thread)
                {
                    return(true);
                }
            }
            return(false);
        }
        public WaitNode Dequeue()
        {
            if (_head == null)
            {
                return(null);
            }

            WaitNode w = _head;

            _head = w.NextWaitNode;
            if (_head == null)
            {
                _tail = null;
            }
            w.NextWaitNode = null;
            return(w);
        }
Beispiel #5
0
	    public WaitNode Dequeue()
		{
			if (_head == null) return null;

		    WaitNode w = _head;
		    _head = w.NextWaitNode;
		    if (_head == null) _tail = null;
		    w.NextWaitNode = null;
		    return w;
		}
Beispiel #6
0
		    public override void LockInterruptibly()
			{
				Thread caller = Thread.CurrentThread;
				lock (this)
				{
                    if (GetHold(caller)) return;
                }
				WaitNode n = new WaitNode();
				n.DoWait(this);
			}
Beispiel #7
0
			public override bool TryLock(TimeSpan timespan)
			{
				Thread caller = Thread.CurrentThread;
				lock (this)
				{
                    if (GetHold(caller)) return true;
                }
			    WaitNode n = new WaitNode();
				return n.DoTimedWait(this, timespan);
			}
Beispiel #8
0
			public void TakeOver(WaitNode node)
			{
				lock (this)
				{
					Debug.Assert(_holds == 1 && _owner == Thread.CurrentThread);
					_owner = node.Owner;
				}
			}
Beispiel #9
0
			public bool Recheck(WaitNode node)
			{
				Thread caller = Thread.CurrentThread;
				lock (this)
				{
                    if(GetHold(caller)) return true;
				    _wq.Enqueue(node);
					return false;
				}
			}
			public void TakeOver(WaitNode node) {}
			public bool Recheck(WaitNode node) { return false; }
 private void DoWait(Action<WaitNode> action)
 {
     int holdCount = Lock.HoldCount;
     if (holdCount == 0)
     {
         throw new SynchronizationLockException();
     }
     WaitNode n = new WaitNode();
     _wq.Enqueue(n);
     for (int i = holdCount; i > 0; i--) Lock.Unlock();
     try
     {
         action(n);
     }
     finally
     {
         for (int i = holdCount; i > 0; i--) Lock.Lock();
     }
 }