예제 #1
0
 public void Enqueue(WaitNode w)
 {
     if (_tail == null)
     {
         _head = _tail = w;
     }
     else
     {
         _tail.NextWaitNode = w;
         _tail = w;
     }
 }
예제 #2
0
        public WaitNode Dequeue()
        {
            if (_head == null)
            {
                return(null);
            }

            var w = _head;

            _head = w.NextWaitNode;
            if (_head == null)
            {
                _tail = null;
            }
            w.NextWaitNode = null;
            return(w);
        }
예제 #3
0
 public void TakeOver(WaitNode node)
 {
     lock (this)
     {
         Debug.Assert(_holds == 1 && _owner == Thread.CurrentThread);
         _owner = node.Owner;
     }
 }
예제 #4
0
 public override bool TryLock(TimeSpan timespan)
 {
     var caller = Thread.CurrentThread;
     lock (this)
     {
         if (GetHold(caller)) return true;
     }
     var n = new WaitNode();
     return n.DoTimedWait(this, timespan);
 }
예제 #5
0
 public override void LockInterruptibly()
 {
     var caller = Thread.CurrentThread;
     lock (this)
     {
         if (GetHold(caller)) return;
     }
     var n = new WaitNode();
     n.DoWait(this);
 }
예제 #6
0
 public bool Recheck(WaitNode node)
 {
     var caller = Thread.CurrentThread;
     lock (this)
     {
         if (GetHold(caller)) return true;
         _wq.Enqueue(node);
         return false;
     }
 }
예제 #7
0
 public void Enqueue(WaitNode w)
 {
     if (_tail == null)
         _head = _tail = w;
     else
     {
         _tail.NextWaitNode = w;
         _tail = w;
     }
 }
예제 #8
0
        public WaitNode Dequeue()
        {
            if (_head == null) return null;

            var w = _head;
            _head = w.NextWaitNode;
            if (_head == null) _tail = null;
            w.NextWaitNode = null;
            return w;
        }
 public void TakeOver(WaitNode node)
 {
 }
예제 #10
0
 public bool Recheck(WaitNode node)
 {
     return false;
 }
예제 #11
0
 private void DoWait(Action<WaitNode> action)
 {
     var holdCount = Lock.HoldCount;
     if (holdCount == 0)
     {
         throw new SynchronizationLockException();
     }
     var n = new WaitNode();
     _wq.Enqueue(n);
     for (var i = holdCount; i > 0; i--) Lock.Unlock();
     try
     {
         action(n);
     }
     finally
     {
         for (var i = holdCount; i > 0; i--) Lock.Lock();
     }
 }