From aa20c34d98d1a7087c74750e5fa38b06700d4f7c Mon Sep 17 00:00:00 2001 From: xtaci Date: Sun, 5 Jan 2020 11:48:19 +0800 Subject: [PATCH] use absolute time --- sess.go | 4 ++-- timedsched.go | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/sess.go b/sess.go index f75e38db..99f5ebb5 100644 --- a/sess.go +++ b/sess.go @@ -183,7 +183,7 @@ func newUDPSession(conv uint32, dataShards, parityShards int, l *Listener, conn } // start per-session updater - SystemTimedSched.Put(sess.update, 0) + SystemTimedSched.Put(sess.update, time.Now()) currestab := atomic.AddUint64(&DefaultSnmp.CurrEstab, 1) maxconn := atomic.LoadUint64(&DefaultSnmp.MaxConn) @@ -593,7 +593,7 @@ func (s *UDPSession) update() { s.uncork() s.mu.Unlock() // self-synchronized timed scheduling - SystemTimedSched.Put(s.update, time.Duration(interval)*time.Millisecond) + SystemTimedSched.Put(s.update, time.Now().Add(time.Duration(interval)*time.Millisecond)) } } diff --git a/timedsched.go b/timedsched.go index fdb398cf..3ff8fc71 100644 --- a/timedsched.go +++ b/timedsched.go @@ -125,10 +125,10 @@ func (ts *TimedSched) prepend() { } } -// Put a function awaiting to be executed -func (ts *TimedSched) Put(f func(), duration time.Duration) { +// Put a function 'f' awaiting to be executed at 'deadline' +func (ts *TimedSched) Put(f func(), deadline time.Time) { ts.prependLock.Lock() - ts.prependTasks = append(ts.prependTasks, timedFunc{f, time.Now().Add(duration)}) + ts.prependTasks = append(ts.prependTasks, timedFunc{f, deadline}) ts.prependLock.Unlock() select {