Skip to content

Commit

Permalink
use absolute time
Browse files Browse the repository at this point in the history
  • Loading branch information
xtaci committed Jan 5, 2020
1 parent 9146e93 commit aa20c34
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
4 changes: 2 additions & 2 deletions sess.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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))
}
}

Expand Down
6 changes: 3 additions & 3 deletions timedsched.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit aa20c34

Please sign in to comment.