*: make use of timecache

This commit is contained in:
Leo Balduf
2017-09-29 00:50:20 +02:00
parent 55b57549a6
commit 89bc479a3b
3 changed files with 7 additions and 54 deletions
+2 -26
View File
@@ -7,13 +7,13 @@ import (
"net"
"runtime"
"sync"
"sync/atomic"
"time"
"gopkg.in/yaml.v2"
"github.com/chihaya/chihaya/bittorrent"
"github.com/chihaya/chihaya/pkg/log"
"github.com/chihaya/chihaya/pkg/timecache"
"github.com/chihaya/chihaya/storage"
)
@@ -146,22 +146,6 @@ func New(provided Config) (storage.PeerStore, error) {
}
}()
// Start a goroutine for updating our cached system clock.
ps.wg.Add(1)
go func() {
defer ps.wg.Done()
t := time.NewTicker(1 * time.Second)
for {
select {
case <-ps.closed:
t.Stop()
return
case now := <-t.C:
ps.setClock(now.UnixNano())
}
}
}()
// Start a goroutine for reporting statistics to Prometheus.
ps.wg.Add(1)
go func() {
@@ -229,10 +213,6 @@ type peerStore struct {
cfg Config
shards []*peerShard
// clock stores the current time nanoseconds, updated every second.
// Must be accessed atomically!
clock int64
closed chan struct{}
wg sync.WaitGroup
}
@@ -263,11 +243,7 @@ func recordGCDuration(duration time.Duration) {
}
func (ps *peerStore) getClock() int64 {
return atomic.LoadInt64(&ps.clock)
}
func (ps *peerStore) setClock(to int64) {
atomic.StoreInt64(&ps.clock, to)
return timecache.NowUnixNano()
}
func (ps *peerStore) shardIndex(infoHash bittorrent.InfoHash, af bittorrent.AddressFamily) uint32 {