public void re_timeout(async_timer asyncTimer) { long absus = asyncTimer._timerHandle.absus; if (null != asyncTimer._timerHandle.node) { _timerQueue.Insert(_timerQueue.ReNewNode(asyncTimer._timerHandle.node, absus, asyncTimer)); } else { asyncTimer._timerHandle.node = _timerQueue.Insert(absus, asyncTimer); } long newAbsus = _timerQueue.First.Key; if (!_looping) { _looping = true; _expireTime = newAbsus; timer_loop(newAbsus); } else if (newAbsus < _expireTime) { _expireTime = newAbsus; timer_reloop(newAbsus); } }
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 }); } }
public void cancel(async_timer asyncTimer) { if (null != asyncTimer._timerHandle.node) { _timerQueue.Remove(asyncTimer._timerHandle.node); asyncTimer._timerHandle.node = null; if (0 == _timerQueue.Count) { _timerCount++; _expireTime = 0; _looping = false; if (_utcMode) { waitable_timer.utcTimer.remove_event(this); } else { waitable_timer.sysTimer.remove_event(this); } } else if (asyncTimer._timerHandle.absus == _expireTime) { _expireTime = _timerQueue.First.Key; timer_reloop(_expireTime); } } }
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 }); } }
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 }); } }
public override void timed_lock(long id, int ms, functional.func <chan_async_state> ntf) { _strand.distribute(delegate() { if (0 == _lockID || id == _lockID) { _lockID = id; _recCount++; ntf(chan_async_state.async_ok); } else if (ms > 0) { async_timer timer = new async_timer(_strand); LinkedListNode <wait_node> it = _waitQueue.AddLast(new wait_node(delegate(chan_async_state state) { timer.cancel(); ntf(state); }, id)); 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); } }); }
public void timed_wait(long id, int ms, mutex_base mutex, functional.func <chan_async_state> ntf) { _strand.distribute(delegate() { if (ms > 0) { async_timer timer = new async_timer(_strand); LinkedListNode <functional.func> node = _waitQueue.AddLast(delegate() { timer.cancel(); mutex.Lock(id, delegate() { ntf(chan_async_state.async_ok); }); }); timer.timeout(ms, delegate() { _waitQueue.Remove(node); ntf(chan_async_state.async_overtime); }); } else { ntf(chan_async_state.async_overtime); } }); }
public void timed_lock_shared(long id, int ms, functional.func <chan_async_state> ntf) { self_strand().distribute(delegate() { if (0 != _sharedMap.Count || 0 == _upgradeMutex._lockID) { find_map(id)._count++; 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_shared)); 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); } }); }
public void timeout(async_timer asyncTimer) { long absus = asyncTimer._timerHandle.absus; asyncTimer._timerHandle.node = _timerQueue.Insert(absus, asyncTimer); if (!_looping) { _looping = true; _expireTime = absus; timer_loop(absus); } else if (absus < _expireTime) { _expireTime = absus; timer_reloop(absus); } }
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)))); } }