示例#1
0
 public override void timed_lock(long id, int ms, functional.func <chan_async_state> ntf)
 {
     self_strand().distribute(delegate()
     {
         if (0 == _sharedMap.Count && (0 == _upgradeMutex._lockID || id == _upgradeMutex._lockID))
         {
             _upgradeMutex._lockID = id;
             _upgradeMutex._recCount++;
             ntf(chan_async_state.async_ok);
         }
         else if (ms > 0)
         {
             async_timer timer             = new async_timer(self_strand());
             LinkedListNode <wait_node> it = _waitQueue.AddLast(new wait_node(delegate(chan_async_state state)
             {
                 timer.cancel();
                 ntf(state);
             }, id, lock_status.st_unique));
             timer.timeout(ms, delegate()
             {
                 functional.func <chan_async_state> waitNtf = it.Value._ntf;
                 _waitQueue.Remove(it);
                 waitNtf(chan_async_state.async_overtime);
             });
         }
         else
         {
             ntf(chan_async_state.async_overtime);
         }
     });
 }
示例#2
0
 private void async_timed_lock_shared_(long id, int ms, Action <bool> ntf)
 {
     if (0 != _sharedMap.Count || 0 == base._lockID)
     {
         find_map(id)._count++;
         ntf(true);
     }
     else if (ms >= 0)
     {
         async_timer timer = new async_timer(self_strand());
         LinkedListNode <wait_node> node = _waitQueue.AddLast(new wait_node()
         {
             _ntf = delegate()
             {
                 timer.cancel();
                 ntf(true);
             },
             _waitHostID = id,
             _status     = lock_status.st_shared
         });
         timer.timeout(ms, delegate()
         {
             _waitQueue.Remove(node);
             ntf(false);
         });
     }
     else
     {
         _waitQueue.AddLast(new wait_node()
         {
             _ntf = () => ntf(true), _waitHostID = id, _status = lock_status.st_shared
         });
     }
 }
示例#3
0
 protected virtual void async_timed_lock_(long id, int ms, Action <bool> ntf)
 {
     if (0 == _lockID || id == _lockID)
     {
         _lockID = id;
         _recCount++;
         ntf(true);
     }
     else if (ms >= 0)
     {
         async_timer timer = new async_timer(_strand);
         LinkedListNode <wait_node> node = _waitQueue.AddLast(new wait_node()
         {
             _ntf = delegate()
             {
                 timer.cancel();
                 ntf(true);
             },
             _id = id
         });
         timer.timeout(ms, delegate()
         {
             _waitQueue.Remove(node);
             ntf(false);
         });
     }
     else
     {
         _waitQueue.AddLast(new wait_node()
         {
             _ntf = () => ntf(true), _id = id
         });
     }
 }
示例#4
0
 protected override void async_timed_lock_(long id, int ms, Action <bool> ntf)
 {
     if (0 == _sharedMap.Count && (0 == base._lockID || id == base._lockID))
     {
         base._lockID = id;
         base._recCount++;
         ntf(true);
     }
     else if (ms >= 0)
     {
         async_timer timer = new async_timer(self_strand());
         LinkedListNode <wait_node> node = _waitQueue.AddLast(new wait_node()
         {
             _ntf = delegate()
             {
                 timer.cancel();
                 ntf(true);
             },
             _waitHostID = id,
             _status     = lock_status.st_unique
         });
         timer.timeout(ms, delegate()
         {
             _waitQueue.Remove(node);
             ntf(false);
         });
     }
     else
     {
         _waitQueue.AddLast(new wait_node()
         {
             _ntf = () => ntf(true), _waitHostID = id, _status = lock_status.st_unique
         });
     }
 }
示例#5
0
 private void async_timed_wait_(long id, int ms, go_mutex mutex, Action <bool> ntf)
 {
     if (ms >= 0)
     {
         async_timer timer = new async_timer(_strand);
         LinkedListNode <tuple <long, go_mutex, Action> > node = _waitQueue.AddLast(new tuple <long, go_mutex, Action>(id, mutex, delegate()
         {
             timer.cancel();
             mutex.async_lock(id, () => ntf(true));
         }));
         timer.timeout(ms, delegate()
         {
             _waitQueue.Remove(node);
             mutex.async_lock(id, () => ntf(false));
         });
     }
     else
     {
         _waitQueue.AddLast(new tuple <long, go_mutex, Action>(id, mutex, () => mutex.async_lock(id, () => ntf(true))));
     }
 }