()
| 29 | } |
| 30 | |
| 31 | func (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 | |
| 63 | func (this *Manager) Add(list *List) { |
| 64 | this.locker.Lock() |
no test coverage detected