2018-08-30 14:25:33 +00:00
|
|
|
package dnsfilter
|
|
|
|
|
|
|
|
import (
|
|
|
|
"sync/atomic"
|
|
|
|
)
|
|
|
|
|
|
|
|
func updateMax(valuePtr *int64, maxPtr *int64) {
|
|
|
|
for {
|
|
|
|
current := atomic.LoadInt64(valuePtr)
|
|
|
|
max := atomic.LoadInt64(maxPtr)
|
|
|
|
if current <= max {
|
|
|
|
break
|
|
|
|
}
|
|
|
|
swapped := atomic.CompareAndSwapInt64(maxPtr, max, current)
|
2018-09-14 13:50:56 +00:00
|
|
|
if swapped {
|
2018-08-30 14:25:33 +00:00
|
|
|
break
|
|
|
|
}
|
|
|
|
// swapping failed because value has changed after reading, try again
|
|
|
|
}
|
|
|
|
}
|