github.com/geph-official/geph2@v0.22.6-0.20210211030601-f527cb59b0df/cmd/geph-client/conntrack.go (about) 1 package main 2 3 import ( 4 "sync" 5 "sync/atomic" 6 ) 7 8 // net.Conn => *int64 9 var trackerMap sync.Map 10 11 func getCounter(key interface{}) *int64 { 12 rv, _ := trackerMap.LoadOrStore(key, new(int64)) 13 return rv.(*int64) 14 } 15 16 func incrCounter(key interface{}) { 17 atomic.AddInt64(getCounter(key), 1) 18 } 19 20 func decrCounter(key interface{}) { 21 atomic.AddInt64(getCounter(key), -1) 22 } 23 24 func readCounter(key interface{}) { 25 atomic.LoadInt64(getCounter(key)) 26 }