mirror of
https://gitclone.com/github.com/MetaCubeX/Clash.Meta
synced 2025-02-24 13:12:26 +08:00
Chore: use only one goroutine to handle statistic (#940)
This commit is contained in:
parent
02d9169b5d
commit
13275b1aa6
@ -10,7 +10,8 @@ var DefaultManager *Manager
|
|||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
DefaultManager = &Manager{}
|
DefaultManager = &Manager{}
|
||||||
DefaultManager.handle()
|
|
||||||
|
go DefaultManager.handle()
|
||||||
}
|
}
|
||||||
|
|
||||||
type Manager struct {
|
type Manager struct {
|
||||||
@ -69,18 +70,13 @@ func (m *Manager) ResetStatistic() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (m *Manager) handle() {
|
func (m *Manager) handle() {
|
||||||
go m.handleCh(&m.uploadTemp, &m.uploadBlip)
|
|
||||||
go m.handleCh(&m.downloadTemp, &m.downloadBlip)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *Manager) handleCh(temp *int64, blip *int64) {
|
|
||||||
ticker := time.NewTicker(time.Second)
|
ticker := time.NewTicker(time.Second)
|
||||||
|
|
||||||
for {
|
for range ticker.C {
|
||||||
<-ticker.C
|
atomic.StoreInt64(&m.uploadBlip, atomic.LoadInt64(&m.uploadTemp))
|
||||||
|
atomic.StoreInt64(&m.uploadTemp, 0)
|
||||||
atomic.StoreInt64(blip, atomic.LoadInt64(temp))
|
atomic.StoreInt64(&m.downloadBlip, atomic.LoadInt64(&m.downloadTemp))
|
||||||
atomic.StoreInt64(temp, 0)
|
atomic.StoreInt64(&m.downloadTemp, 0)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user