Example #1
0
        public override void unlock(long id, functional.func ntf)
        {
            _strand.distribute(delegate()
            {
#if DEBUG
                Trace.Assert(id == _lockID);
#endif
                if (0 == --_recCount)
                {
                    if (0 != _waitQueue.Count)
                    {
                        _recCount            = 1;
                        wait_node queueFront = _waitQueue.First.Value;
                        _waitQueue.RemoveFirst();
                        _lockID = queueFront._id;
                        queueFront._ntf(chan_async_state.async_ok);
                    }
                    else
                    {
                        _lockID = 0;
                    }
                }
                ntf();
            });
        }
Example #2
0
 public void unlock_shared(long id, functional.func ntf)
 {
     self_strand().distribute(delegate()
     {
         if (0 == --find_map(id)._count)
         {
             _sharedMap.Remove(id);
             if (0 == _sharedMap.Count && 0 != _waitQueue.Count)
             {
                 LinkedList <functional.func <chan_async_state> > ntfs = new LinkedList <functional.func <chan_async_state> >();
                 wait_node queueFront = _waitQueue.First.Value;
                 _waitQueue.RemoveFirst();
                 ntfs.AddLast(queueFront._ntf);
                 if (lock_status.st_shared == queueFront._status)
                 {
                     _upgradeMutex._lockID = 0;
                     find_map(queueFront._waitHostID)._count++;
                     for (LinkedListNode <wait_node> it = _waitQueue.First; null != it;)
                     {
                         if (lock_status.st_shared == it.Value._status)
                         {
                             find_map(it.Value._waitHostID)._count++;
                             ntfs.AddLast(it.Value._ntf);
                             LinkedListNode <wait_node> oit = it;
                             it = it.Next;
                             _waitQueue.Remove(oit);
                         }
                         else
                         {
                             it = it.Next;
                         }
                     }
                 }
                 else
                 {
                     _upgradeMutex._lockID = queueFront._waitHostID;
                     _upgradeMutex._recCount++;
                 }
                 while (0 != ntfs.Count)
                 {
                     ntfs.First.Value(chan_async_state.async_ok);
                     ntfs.RemoveFirst();
                 }
             }
         }
         ntf();
     });
 }
Example #3
0
 protected virtual void async_unlock_(long id, Action ntf)
 {
     Debug.Assert(id == _lockID);
     if (0 == --_recCount)
     {
         if (0 != _waitQueue.Count)
         {
             _recCount = 1;
             wait_node queueFront = _waitQueue.First.Value;
             _waitQueue.RemoveFirst();
             _lockID = queueFront._id;
             queueFront._ntf();
         }
         else
         {
             _lockID = 0;
         }
     }
     ntf();
 }
Example #4
0
 private void async_unlock_shared_(long id, Action ntf)
 {
     if (0 == --find_map(id)._count)
     {
         _sharedMap.Remove(id);
         if (0 == _sharedMap.Count && 0 != _waitQueue.Count)
         {
             _mustTick = true;
             wait_node queueFront = _waitQueue.First.Value;
             _waitQueue.RemoveFirst();
             queueFront._ntf();
             if (lock_status.st_shared == queueFront._status)
             {
                 base._lockID = 0;
                 find_map(queueFront._waitHostID)._count++;
                 for (LinkedListNode <wait_node> it = _waitQueue.First; null != it;)
                 {
                     if (lock_status.st_shared == it.Value._status)
                     {
                         find_map(it.Value._waitHostID)._count++;
                         it.Value._ntf();
                         LinkedListNode <wait_node> oit = it;
                         it = it.Next;
                         _waitQueue.Remove(oit);
                     }
                     else
                     {
                         it = it.Next;
                     }
                 }
             }
             else
             {
                 base._lockID = queueFront._waitHostID;
                 base._recCount++;
             }
             _mustTick = false;
         }
     }
     ntf();
 }