Пример #1
0
 private void begin_timer(long nowus, long absus, long period)
 {
     _beginTick = nowus;
     if (nowus < absus)
     {
         _timerCount++;
         _timerHandle.absus  = absus;
         _timerHandle.period = period;
         if (_utcMode)
         {
             _strand._utcTimer.timeout(this);
         }
         else
         {
             _strand._sysTimer.timeout(this);
         }
     }
     else
     {
         int tmId = ++_timerCount;
         _timerHandle.absus  = absus;
         _timerHandle.period = period;
         _strand.post(delegate()
         {
             if (tmId == _timerCount)
             {
                 timer_handler();
             }
         });
     }
 }
Пример #2
0
 public void timer_handler(int id)
 {
     if (id != _timerCount)
     {
         return;
     }
     _strand.post(delegate()
     {
         if (id == _timerCount)
         {
             _expireTime = long.MinValue;
             while (0 != _timerQueue.Count)
             {
                 MapNode <long, async_timer> first = _timerQueue.First;
                 if (first.Key > (_utcMode ? utc_tick.get_tick_us() : system_tick.get_tick_us()))
                 {
                     _expireTime = first.Key;
                     timer_loop(_expireTime);
                     return;
                 }
                 else
                 {
                     first.Value._timerHandle.node = null;
                     first.Value.timer_handler();
                     _timerQueue.Remove(first);
                 }
             }
             _looping = false;
         }
     });
 }
Пример #3
0
 internal void async_lock(long id, Action ntf)
 {
     if (_strand.running_in_this_thread())
     {
         if (!_mustTick)
         {
             async_lock_(id, ntf);
         }
         else
         {
             _strand.add_last(() => async_lock_(id, ntf));
         }
     }
     else
     {
         _strand.post(() => async_lock_(id, ntf));
     }
 }
Пример #4
0
 internal void async_wait(long id, go_mutex mutex, Action ntf)
 {
     mutex.async_unlock(id, delegate()
     {
         if (_strand.running_in_this_thread())
         {
             if (!_mustTick)
             {
                 _waitQueue.AddLast(new tuple <long, go_mutex, Action>(id, mutex, () => mutex.async_lock(id, ntf)));
             }
             else
             {
                 _strand.add_last(() => _waitQueue.AddLast(new tuple <long, go_mutex, Action>(id, mutex, () => mutex.async_lock(id, ntf))));
             }
         }
         else
         {
             _strand.post(() => _waitQueue.AddLast(new tuple <long, go_mutex, Action>(id, mutex, () => mutex.async_lock(id, ntf))));
         }
     });
 }
Пример #5
0
        private void tick_timer(long absus)
        {
            int tmId = ++_timerCount;

            _timerHandle.absus  = absus;
            _timerHandle.period = 0;
            _strand.post(delegate()
            {
                if (tmId == _timerCount)
                {
                    timer_handler();
                }
            });
        }
Пример #6
0
 private void begin_timer(long tick, long dueTime, int period)
 {
     if (null == _timer)
     {
         _strand.hold_work();
     }
     _timer = new Timer(delegate(object state)
     {
         _strand.post(delegate()
         {
             if ((int)state == _timerCount)
             {
                 _beginTick = 0;
                 _onTopCall = true;
                 if (_isInterval)
                 {
                     functional.func handler = _handler;
                     handler();
                     if ((int)state == _timerCount)
                     {
                         tick   += period;
                         dueTime = tick - system_tick.get_tick_ms();
                         begin_timer(tick, dueTime > 0 ? dueTime : 0, period);
                     }
                 }
                 else
                 {
                     functional.func handler = _handler;
                     _handler = null;
                     _timer   = null;
                     _strand.release_work();
                     handler();
                 }
                 _onTopCall = false;
             }
         });
     }, _timerCount, dueTime, 0);
 }