MCPcopy Create free account
hub / github.com/GoEdgeLab/EdgeNode / init

Method init

internal/utils/expires/manager.go:31–61  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

29}
30
31func (this *Manager) init() {
32 var lastTimestamp = int64(0)
33 for range this.ticker.C {
34 var currentTime = time.Now().Unix()
35 if lastTimestamp == 0 {
36 lastTimestamp = currentTime - 86400 // prevent timezone changes
37 }
38
39 if currentTime >= lastTimestamp {
40 for i := lastTimestamp; i <= currentTime; i++ {
41 this.locker.Lock()
42 for list := range this.listMap {
43 list.GC(i)
44 }
45 this.locker.Unlock()
46 }
47 } else {
48 // 如果过去的时间比现在大,则从这一秒重新开始
49 for i := currentTime; i <= currentTime; i++ {
50 this.locker.Lock()
51 for list := range this.listMap {
52 list.GC(i)
53 }
54 this.locker.Unlock()
55 }
56 }
57
58 // 这样做是为了防止系统时钟突变
59 lastTimestamp = currentTime
60 }
61}
62
63func (this *Manager) Add(list *List) {
64 this.locker.Lock()

Callers 1

NewManagerFunction · 0.45

Calls 4

UnixMethod · 0.80
GCMethod · 0.65
LockMethod · 0.45
UnlockMethod · 0.45

Tested by

no test coverage detected